authlogic flash [:notice]不会出现在黄瓜webrat步骤中

时间:2010-07-13 19:53:44

标签: ruby-on-rails cucumber authlogic bdd webrat

我正在使用黄瓜运行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] not working

我的设置是

*** LOCAL GEMS ***

actionmailer(2.3.8)

actionpack(2.3.8)

activerecord(2.3.8)

activeresource(2.3.8)

activesupport(2.3.8)

authlogic(2.1.5)

builder(2.1.2)

配置(1.1.0)

黄瓜(0.8.4,0.8.3)

cucumber-rails(0.3.2)

database_cleaner(0.5.2)

declarative_authorization(0.4.1)

diff-lcs(1.1.2)

小黄瓜(2.1.2,2.0.2)

json_pure(1.4.3)

launchy(0.3.5)

mysql(2.8.1)

nokogiri(1.4.2)

paperclip(2.3.3)

泡菜(0.3.0)

rack(1.2.1,1.1.0)

rack-test(0.5.4)

rails(2.3.8)

rake(0.8.7)

rspec(1.3.0)

rspec-rails(1.3.2)

语法(1.0.0)

term-ansicolor(1.0.5)

thoughtbot-factory_girl(1.2.2)

trollop(1.16.2)

webrat(0.7.1)

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

我可以做些什么让我的黄瓜步骤通过!

感谢您的帮助

4 个答案:

答案 0 :(得分: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 =>登陆成功!' < - 完全工作

答案 1 :(得分:0)

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

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

可能就是你要找的东西。

答案 2 :(得分:0)

我相信这个问题将在Rails 2.3.9中修复。它与在同一请求中设置cookie和会话有关。有关详细信息,请参阅this ticket

与此同时,您可以使用this gist作为临时修复。

答案 3 :(得分:0)

感谢raynb向我指出了正确的方向。但不幸的是,这个解决方案没有用,但是我发现这个页面把所有东西都放在了cucumber.rb ...这让它疯狂了......

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