在运行“使用Capybara进行应用程序测试”一书中的示例时,我收到了错误
step_definitions/steps.rb:5: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
... :with => search_term click_on 'search-btn'
... ^
我的 steps.rb 如下所示:
Given(/^I am on the YouTube home page$/) do
visit 'http://www.youtube.com'
end
When(/^I search for "(.*?)"$/) do
|search_term| fill_in 'search_query', :with => search_term click_on 'search-btn'
end
Then(/^videos of large rodents are returned$/) do
page.should have_content 'Largest Rodent'
现在我遇到了新问题
根据: betterspecs .org /#expect
我改变了“然后行”为.. 然后(/ ^大型啮齿动物的视频返回$ /)做 期待(页面).to have_content'最大的啮齿动物'
我得到了: Spec :: Expectations :: ExpectationNotMetError:预计会在“稍后提醒我”中查找文本“最大的啮齿动物”来自YouTube的Google隐私提醒,PL SearchSign in Search主页趋势BEST OF YOUTUBE ./features/step_definitions/steps.rb:10:in`/ ^大型啮齿动物的视频被退回$ /'
答案 0 :(得分:0)
fill_in
和click_on
是两种截然不同的方法。您的代码应如下所示:
When(/^I search for "(.*?)"$/) do |search_term|
fill_in 'search_query', :with => search_term
click_on 'search-btn'
end
答案 1 :(得分:0)
谢谢它帮了但是......另一个问题出现了:(
./features/step_definitions/steps.rb:10:in /^videos of large rodents are returned$/'
./features/youtube_search.feature:5:in
然后返回大型啮齿动物的视频'
弃用:使用来自rspec-expectations'的should
没有明确启用
:should
语法
我改变了行:
然后(/ ^大型啮齿动物的视频返回$ /)做
page.should have_content'最大的啮齿动物'
端
page.sould on page.expect但没有帮助
我也更改了文字"最大的啮齿动物"敌人:(并没有帮助:(