Ruby on Rails RSpec中未定义`respond_with`方法,这是怎么回事呢?
- 内容介绍
- 文章标签
- 相关推荐
本文共计282个文字,预计阅读时间需要2分钟。
我在按照教程+http://apionrails.icalialabs.com/book/chapter_three 进行操作时,运行控制器测试包 exec rspec 规范时,遇到了未定义的方法错误。错误信息如下:Failures: Api: V1: UsersController GET
我正在按照教程 apionrails.icalialabs.com/book/chapter_three但是当我运行控制器测试包exec rspec规范/控制器时,我得到未定义的方法错误:
Failures: Api::V1::UsersController GET #show Failure/Error: it { should respond_with 200 } NoMethodError: undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x00000005d6f650> # ./spec/controllers/api/v1/users_controller_spec.rb:17:in `block (3 levels) in <top (required)>' Finished in 0.08435 seconds 2 examples, 1 failure
请帮忙
编辑:
以下是我的spec文件的内容
users_controller_spec.rb
require 'spec_helper' describe Api::V1::UsersController do before(:each) { request.headers['Accept'] = "application/vnd.marketplace.v1" } describe "GET #show" do before(:each) do @user = FactoryGirl.create :user get :show, id: @user.id, format: :json end it "returns the information about a reporter on a hash" do user_response = JSON.parse(response.body, symbolize_names: true) expect(user_response[:email]).to eql @user.email end it { should respond_with 200 } end end 我有同样的问题并解决了它.看起来像使用旧版本的shoulda-matchers有帮助.我将Gemfile更改为gem“shoulda-matchers”,“〜> 2.5”
本文共计282个文字,预计阅读时间需要2分钟。
我在按照教程+http://apionrails.icalialabs.com/book/chapter_three 进行操作时,运行控制器测试包 exec rspec 规范时,遇到了未定义的方法错误。错误信息如下:Failures: Api: V1: UsersController GET
我正在按照教程 apionrails.icalialabs.com/book/chapter_three但是当我运行控制器测试包exec rspec规范/控制器时,我得到未定义的方法错误:
Failures: Api::V1::UsersController GET #show Failure/Error: it { should respond_with 200 } NoMethodError: undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x00000005d6f650> # ./spec/controllers/api/v1/users_controller_spec.rb:17:in `block (3 levels) in <top (required)>' Finished in 0.08435 seconds 2 examples, 1 failure
请帮忙
编辑:
以下是我的spec文件的内容
users_controller_spec.rb
require 'spec_helper' describe Api::V1::UsersController do before(:each) { request.headers['Accept'] = "application/vnd.marketplace.v1" } describe "GET #show" do before(:each) do @user = FactoryGirl.create :user get :show, id: @user.id, format: :json end it "returns the information about a reporter on a hash" do user_response = JSON.parse(response.body, symbolize_names: true) expect(user_response[:email]).to eql @user.email end it { should respond_with 200 } end end 我有同样的问题并解决了它.看起来像使用旧版本的shoulda-matchers有帮助.我将Gemfile更改为gem“shoulda-matchers”,“〜> 2.5”

