黄瓜、rspec、webrat if else 在匹配器上
我的黄瓜测试套件中有一个步骤定义,用于对用户进行身份验证并尝试加快我的测试套件的速度,我希望此步骤检查用户是否已通过身份验证。也许这是一个坏主意,因为这意味着测试可能相互依赖......我不知道。但我该怎么做呢?不幸的是,我对 Ruby 不太熟悉。
我希望我可以在 DOM 中渲染一个类,这样我就可以使用 have_selector 或其他东西对此进行测试。这也可能是一个坏主意......
Given /^I am authenticated as a "([^"]*)" user$/ do |role|
#TODO: only do this if the user is not authenticated
visit('/login')
fill_in "name", :with => "something"
fill_in "pass", :with => "password"
click_button
response_body.should contain("Log out")
end
I have a step definition in my cucumber test suite that authenticates the user and to try and speed up my test suite, I want this step to check the user is already authenticated. Perhaps this is a bad idea because it means tests may depend on each other... I don't know. But how would I do this? I am not fluent in Ruby, unfortunately.
I am hoping that I can render a class in the DOM so I can test against this with have_selector or something. This might also be a bad idea too...
Given /^I am authenticated as a "([^"]*)" user$/ do |role|
#TODO: only do this if the user is not authenticated
visit('/login')
fill_in "name", :with => "something"
fill_in "pass", :with => "password"
click_button
response_body.should contain("Log out")
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,这将是一个坏主意。但是,如果您确实想这样做,正确的方法是检查页面上的任何类型的文本,例如您可以在状态栏上显示已登录的用户名。这是正确的方法,因为它模拟了人类的行为,例如 - 哦,这是我的用户名 - 这意味着我已经登录了:)
您的步骤如下所示:
You're right this would be a bad idea. But if you really want to do it the correct way would be checking any kind of text on the page, for example you can have status bar with logged in username. This would be correct way because it simulates the behavior of a human, something like - oh, here is my username - it means that I'm already logged in:)
Here is how your step could look like: