【发布时间】:2015-08-27 07:15:12
【问题描述】:
鉴于我在使用 devise 时尝试编写一个简单的 rspec 测试,我似乎保留了 NoMethodError: undefined method sign_in 我有以下设置,但似乎无法解决这个问题。我确实遇到了另一个与此 Rails, Devise, Rspec: Undefined method 'sign_in' 类似的问题,并且我确定我已启用 config.infer_spec_type_from_file_location!,如我的 rails helper 的 sn-p 中所示
规范助手
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
导轨助手
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
支持/设计
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: 未定义的方法 `sign_in'
/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:inblock (2 级) in '
【问题讨论】:
标签: ruby-on-rails rspec devise