古いテストをリファクタリングしようとしました。以下のコード:
describe "translation result", :js => true do
it "translations should be shown as links to translations in second way" do
visit '/'
fill_in('query-field', :with => 'kOŃ')
click_button('search-button')
sleep(7)
page.all(:css, '.result a').size.should eq(2)
page.find('.result a').text.should == 'horse'
end
end
以下の情報を返します。
1) translation result translations should be shown as links to translations in second way
Failure/Error: page.find('.result a').text.should == 'horse'
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching css ".result a"
# ./spec/integration/result_spec.rb:12:in `block (2 levels) in <top (required)>'
describe ブロックの「find メソッド」によって返されるものから要素を取得しようとしました。それは私が以下に示すようにそれをやろうとしたことを意味します:
page.find('.result a').first.text.should == 'horse'
また
page.find('.result a')[0].text.should == 'horse'
2つの要素を取得すると、そのうちの1つを取得できると思うので、そうしました。私の論理は正しいと思いますか? 問題を解決する方法。コード付きのレポはこちら: https://github.com/mtczerwinski/dict-app