4

我正在运行 rails 3.0.0, rspec-rails 2.0.0.beta.20, webrat 0.7.2.beta.1, cucumber-rails 0.3.2 我有这种情况:

Scenario:
  Given I am on the new account page
  And I fill in "Name" with "John Doe"
  When I press "Create"
  Then I should be on the access page

当我运行它时,我得到:

expected: "/access",
got: "/accounts"

就像它不遵循控制器中的 redirect_to 一样:

#accounts_controller.rb
def create
  @account = Account.new(params[:account])
  if @account.save
    flash[:notice] = "Saved!"
    redirect_to access_url  
  else
    flash[:alert] = "Error!"
    render :new
  end
end

我错过了一步吗?我认为 webrat 遵循所有重定向。谢谢

使用launchy gem,我得到一个页面,上面写着:

“您正在被重定向”,带有指向 access_path 的链接

?

4

3 回答 3

2

不确定这是否适用于 Rails 3,但你可以试试这个方法“follow_redirect!”

于 2010-09-03T14:20:49.167 回答
0

我找到了这个对我有帮助的解决方案。

http://baldowl.github.com/2010/12/06/coercing-cucumber-and-webrat-to-cooperate.html

于 2011-02-07T05:08:49.287 回答
0

这是在这里回答的:

Webrat 和 Rails:在 click_button 之后使用 assert_contain 给我“你正在被重定向”

解决方案对我有用。

于 2011-01-05T04:36:45.373 回答