我开始通过黄瓜研究 BDD。(使用 Rails-3,gem 'cucumber-rails')
我想在成功登录时重定向到用户个人资料页面(/users/id)。
我在控制器中定义为 (redirect_to user_path(@user)) 和我在黄瓜中定义的一样 (page.current_path.should == user_path(@user))
在我的 step_definition
Given /^a user visits the signin page$/ do
visit signin_path
end
When /^he log in as "(.*)\/(.*)"$/ do |email, password|
@email = email
fill_in "email", with: email
fill_in "password", with: password
click_button "Login"
end
Then /^he should see a signin link$/ do
page.should have_link('Sign in', href: signin_path)
end
Then /^he should see his profile page$/ do
@user = User.where("email = ?", @email)
page.current_path.should == user_path(@user)
end
在我的控制器中
class SessionsController < ApplicationController
def create
@user = User.find_by_email(params[:session][:email].downcase)
if @user && @user.authenticate(params[:session][:password])
sign_in @user
redirect_to user_path(@user)
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
end
现在运行黄瓜时,我收到此错误:
expected: "/users/%23%3CActiveRecord::Relation:0x000000062fbec0%3E"
got: "/users/4" (using ==) (RSpec::Expectations::ExpectationNotMetError)
在我的 features/support/env.rb 中:
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/rails'
require 'rspec/expectations'
请回答我做错的地方。