NoMethodError 未定义方法 sign_in rspec 设计
NoMethodError undefined method sign_in rspec devise
考虑到我正在尝试编写一个简单的 rspec 测试,同时使用设计,我似乎保留了 NoMethodError: undefined method sign_in 我有以下设置,但似乎无法解决这个问题。我确实遇到了另一个与此 Rails, Devise, Rspec: Undefined method 'sign_in' 类似的问题,我确定我已启用 config.infer_spec_type_from_file_location!
,如我的 rails 助手
的代码片段所示
规格助手
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
end
rails帮手
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
#
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = false
config.infer_spec_type_from_file_location!
end
support/devise
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controllers
end
controller_spec
describe UsersController do
before :each do
@user = FactoryGirl.create(:user, :admin)
sign_in @user
end
context "HTML" do
describe "GET index" do
it "assigns all users as @users" do
user = @user
get :index, {}
assigns(:user).should eq([user])
end
end
end
end
我不断得到:
测试开始于 10:15 上午 ...
NoMethodError: undefined method `sign_in' for
/home/trcdev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.2.1/lib/action_dispatch/testing/assertions/routing.rb:171:in
method_missing' ./spec/controllers/users_controller_spec.rb:4:in
block (2 levels) in '
你没有显示它,所以我猜它不存在。您需要 require "rails_helper"
在您的 controller_spec
.
考虑到我正在尝试编写一个简单的 rspec 测试,同时使用设计,我似乎保留了 NoMethodError: undefined method sign_in 我有以下设置,但似乎无法解决这个问题。我确实遇到了另一个与此 Rails, Devise, Rspec: Undefined method 'sign_in' 类似的问题,我确定我已启用 config.infer_spec_type_from_file_location!
,如我的 rails 助手
规格助手
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
end
rails帮手
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
#
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = false
config.infer_spec_type_from_file_location!
end
support/devise
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controllers
end
controller_spec
describe UsersController do
before :each do
@user = FactoryGirl.create(:user, :admin)
sign_in @user
end
context "HTML" do
describe "GET index" do
it "assigns all users as @users" do
user = @user
get :index, {}
assigns(:user).should eq([user])
end
end
end
end
我不断得到:
测试开始于 10:15 上午 ...
NoMethodError: undefined method `sign_in' for
/home/trcdev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.2.1/lib/action_dispatch/testing/assertions/routing.rb:171:in
method_missing' ./spec/controllers/users_controller_spec.rb:4:in
block (2 levels) in '
你没有显示它,所以我猜它不存在。您需要 require "rails_helper"
在您的 controller_spec
.