身份验证测试生成错误,我无法理解。它说单元测试断言错误。
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:0xba527604>authentication_pages_spec.rb
describe "authorization" do
describe "for non-signed-in users" do
let(:user) { FactoryGirl.create(:user) }
describe "in the Users controller" do
describe "visiting the edit page" do
before { visit edit_user_path(user) }
it { should have_title('Sign in') }
end
describe "submitting to the update action" do
before { patch user_path(user) }
specify { expect(response).to redirect_to(signin_path) }
end
end
end
enduser_controller.rb
授权应用程序代码使用一个前置筛选器,它使用before_action命令安排在给定操作之前调用特定方法。(用于前置过滤器的命令以前称为before_filter,但Rails核心团队决定重命名它,以强调过滤器发生在特定控制器操作之前。)为了要求用户登录,我们定义了一个signed_in_user方法并使用before_action :signed_in_user调用它,如下所示
class UsersController < ApplicationController
before_action :signed_in_user, only: [:edit, :update]
private
def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
end
# Before filters
def signed_in_user
redirect_to signin_url, notice: "Please sign in." unless signed_in?
end
end发布于 2014-07-17 14:33:49
尝试将下面的行添加到您的gem文件中,并从您的gem文件中删除旧的“”行。
gem "rspec-rails", '~> 2.14.0.rc1'然后运行这些命令,
$ bundle update
$ bundle install然后再检查一下测试结果。
https://stackoverflow.com/questions/24801396
复制相似问题