0

我正在用黄瓜运行 BDD 步骤来实现我的 autlogic 登录行为。

 Scenario: log in
Given a registered user: "test@test.com" with password: "p@ssword" exists
And I am on the homepage
When I follow "Log in"
And I fill in "Username" with "test@test.com"
And I fill in "Password" with "p@ssword"
And I open the page
And I press "Login"
And I open the page
Then I should see "Login successful!"
And I should see "Logout"

这是我的场景,当我击中

Then I should see "Login successful!"

我的黄瓜步骤失败了,但只在 webrat 中。我用launchy进行了调试,当网页出现时确实没有消息,但在开发模式下,当我运行脚本/服务器时,我看到了我的消息。我的控制器看起来像这样

 def create
@user_session = UserSession.new(params[:user_session])
  if @user_session.save
    flash[:notice] = "Login successful!"
   redirect_to root_url
  else
    render :action => 'new'
  end

结尾

是的,我看到了这个 http://github.com/binarylogic/authlogic/issuesearch?state=open&q=cucumber+flash#issue/142 并且不明白这对我有什么帮助,这也没有帮助

Rails/Cucumber/Webrat:redirect_to,flash[:notice] 不工作

我的设置是

*** LOCAL GEMS ***

actionmailer (2.3.8)

动作包 (2.3.8)

活动记录(2.3.8)

主动资源(2.3.8)

主动支持 (2.3.8)

授权逻辑(2.1.5)

建设者(2.1.2)

配置 (1.1.0)

黄瓜 (0.8.4, 0.8.3)

黄瓜导轨 (0.3.2)

database_cleaner (0.5.2)

声明性授权(0.4.1)

diff-lcs (1.1.2)

小黄瓜 (2.1.2, 2.0.2)

json_pure (1.4.3)

发射 (0.3.5)

mysql (2.8.1)

nokogiri (1.4.2)

回形针 (2.3.3)

泡菜(0.3.0)

机架(1.2.1、1.1.0)

机架测试(0.5.4)

导轨 (2.3.8)

耙子 (0.8.7)

rspec (1.3.0)

rspec-rails (1.3.2)

语法 (1.0.0)

术语 ansicolor (1.0.5)

思想机器人工厂女孩 (1.2.2)

巨魔(1.16.2)

韦拉特 (0.7.1)

ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux] gem 1.3.7 在 Ubuntu 上运行

我该怎么做才能让我的黄瓜步骤通过!

谢谢你的帮助

4

4 回答 4

1

而不是线

flash[:notice] = "Login successful!"   
redirect_to root_url

只是尝试渲染它而不是重定向它。

flash[:notice] = "Login successful!"   
render :action => :root_url

在这样做时,它似乎记得 flash[:notice]

我无法获得 --> redirect_to root_url, :flash => { :notice => 'not found' }, :notice => 登录成功!' <-- 完全工作

于 2011-01-18T03:50:29.317 回答
0

看起来 rails 2.3.8 改变了显示通知的方法..

redirect_to(root_url, :notice => 'Login successful!')

可能是你正在寻找的。

于 2010-07-13T21:59:14.197 回答
0

我相信这个问题会在 Rails 2.3.9 中得到解决。它与在同一个请求中设置 cookie 和会话有关。详情见这张票

同时,您可以将此要点用作临时修复。

于 2010-07-14T21:09:45.070 回答
0

感谢 raynb,他为我指明了正确的方向。但不幸的是,这个解决方案没有奏效,但我发现这个页面将所有内容都放在 cucumber.rb 中......这让它现在运行很疯狂......

https://webrat.lighthouseapp.com/projects/10503-webrat/tickets/383-reset_session-and-webrat-dont-play-nicely-with-one-another

于 2010-07-18T14:17:28.893 回答