私は、次のステップがあります。のRails +キュウリ+カピバラ:HTMLテーブルと期待されるテーブルを比較
Then I should see the following games:
| soccer | 94040 | "friendly" |
| basketball | 94050 | "competition"|
をそして、私は、次のステップ定義している:私はputs table_results
を行う場合
Then /^I should see the following games:$/ do |expected_table|
table_results = page.find('#games_results_table')
end
私が手に:
#<Capybara::Element tag="table" path="/html/body/div[2]/table">
私はこれを試して、expected_tableとtable_resultsを比較しようとしました:
expected_table.diff!(table_results)
しかし、私はこのエラーを取得する:テーブルをレンダリングしているビューは、このあること
undefined method `transpose' for #<Capybara::Element tag="table" path="/html/body/div[2]/table"> (NoMethodError)
お知らせ:
<div class="page-header">
<h1>Games</h1>
<table id="games_results_table" class="table table-striped">
<tr>
<th>Sport Type</th>
<th>Zip Code</th>
<th>Description</th>
</tr>
<% @games.each do |game| %>
<tr>
<td><%= game.sport_type %></td>
<td><%= game.zip_code %></td>
<td><%= game.description %></td>
</tr>
<% end %>
</table>
</div>
私が間違って何をしているのですか?
It takes a single argument which it expects to be an Array of Array representing rows and columns. If all the values are equal, the step definition passes. If not, the step definition fails and a diff is printed out.
ですから、配列の配列にあなたのカピバラテーブルをマップする必要がある、のようなもの:あなたはこれを実験する必要があり
table_results = page.find('#games_results_table tr').map do |row|
row.children.map do |cell|
cell.text
end
end
table#diff!
法上のthe Cucumber bookから
これ[要旨](https://gist.github.com/denmarkin/1334262)のテーブルを比較した実施例を提供しますあなたの生成したHTMLのテーブルへのあなたの機能。 – Ritchie