【问题标题】:Rspec-Rails-Capybara. "Response" objectRspec-Rails-Capybara。 “响应”对象
【发布时间】:2014-08-14 16:31:28
【问题描述】:

我现在正在阅读 M. Hart 的 Rails 教程。由于补丁请求后测试重定向出错,在 9.2.1 停止。使用 Ruby on Rails 4.1 框架,我的应用程序的瑰宝:

  ruby '2.0.0'
  gem 'rails', '4.1.0'
  ...
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails', '4.2.1'
  gem 'rspec-rails', '2.13.1'

我有用户控制器

class UsersController < ApplicationController
  before_action :signed_in_user, only: [:edit, :update]

  #actions...
  private
    #strong parameters...

    def signed_in_user
      redirect_to signin_url, notice: "Please sign in." unless signed_in?
    end
end

我的 Rspec+Capybara 重定向测试:

describe "Authentication" do
  subject { page }

  describe "authorization" do
    describe "for non-signed-in users" do
      let(:user) { FactoryGirl.create(:user) }

      describe "in the Users controller" do
        #...
        describe "submitting to the update action" do
          before { patch user_path(user) }
          specify { expect(response).to redirect_to(signin_path) }
        end
      end
    #...
end

当我运行 rspec spec/

 1) Authentication authorization for non-signed-in users in the Users controller submitting to the update action 
     Failure/Error: specify { expect(response).to redirect_to(signin_path) }
     NoMethodError:
       undefined method `assertions' for #<RSpec::Rails::TestUnitAssertionAdapter::AssertionDelegator:0xae34810>
     # ./spec/requests/authentication_pages_spec.rb:23:in `block (6 levels) in <top (required)>'

怎么了?

【问题讨论】:

    标签: ruby-on-rails rspec tdd capybara


    【解决方案1】:

    用途:

    gem "rspec-rails", '~> 2.14.0'
    

    根据之前回答的问题:

    Rails 4 and RSpec, undefined method `assertions' in routing spec

    请注意,gem 不再是 rc,因此您应该可以使用发布版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      • 2015-12-20
      • 1970-01-01
      • 2019-08-25
      相关资源
      最近更新 更多