rspec失败了

时间:2011-06-23 00:57:10

标签: ruby-on-rails controller rspec

没有rspecs开始失败的地方,如:

ruby​​ 1.8.7,rails 3.06。

~/.rvm/rubies/ree-1.8.7-2011.03/bin/ruby -S bundle exec rspec spec/controllers/gift_cards_controller_spec.rb:30
No DRb server is running. Running in local process instead ...
Run filtered including {:line_number=>30}
F

Failures:

  1) GiftCardsController POST to :create for a logged-in User with valid attributes 
     Failure/Error: it { should respond_with(:redirect) }
     NoMethodError:
       undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0x11af4324>
     # ./spec/controllers/gift_cards_controller_spec.rb:30

Finished in 0.93776 seconds
1 example, 1 failure

2 个答案:

答案 0 :(得分:9)

不是#repond_with一个Shoulda匹配器吗?确保它在Gemfile中的RSpec之后出现:

group :development, :test do
  gem 'rspec-rails', '2.4.1'
  gem 'shoulda-matchers', '1.0.0.beta1'
end

答案 1 :(得分:0)

将旧的rails应用升级到rails 5.0后出现此错误。然后将以下配置添加到spec_helper.rb中,现在它正常工作。

Shoulda::Matchers.configure do |config|
   config.integrate do |with|
     with.test_framework :rspec
     with.library :rails
   end
end