Tôi đã có một spec/controllers/add_to_carts_spec.rb
:phương pháp xác định 'sign_in' cho # <RSpec :: Lõi :: ExampleGroup :: Nested_1 :: Nested_1: 0x1057fd428> lỗi khi cố gắng thiết lập RSpec với lập mưu
require 'spec_helper'
describe CartItemsController do
before (:each) do
@user = Factory(:user)
sign_in @user
end
describe "add stuff to the cart" do
it "should add a product to the cart" do
product = FactoryGirl.create(:product)
visit products_path(product)
save_and_open_page
click_on('cart_item_submit')
end
end
end
và /spec/support/spec_helper.rb
:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = true
end
... mà cũng tải /spec/support/devise.rb
:
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
Guard là chạy trong nền và tiếp tục ném điều này:
Failures:
1) CartItemsController add stuff to the cart should add a product to the cart
Failure/Error: sign_in @user
NoMethodError:
undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x1057fd428>
# ./spec/controllers/add_to_carts_spec.rb:7
Tôi đã dành vài giờ cuối cùng thử các điều chỉnh cấu hình khác nhau và các cú pháp khác nhau nhưng dường như không có gì thay đổi. Bất kỳ ý tưởng?
(chỉnh sửa để phản ánh lỗi mới hơn)
Đó là thông số bộ điều khiển vì vậy tôi hy vọng nó hoạt động. – solnic
Cảm ơn, bạn đã đúng. Tôi đã nhầm lẫn hai loại thông số kỹ thuật. Tôi đã sử dụng capybara để truy cập vào các trang và do đó sử dụng cơ chế phiên của nó, nhưng cố gắng đăng nhập vào người dùng như tôi làm trong thông số kỹ thuật điều khiển của mình. capybara không sử dụng hoặc có quyền truy cập vào những người đó. –