2010-10-27 19 views
7

Bu kod:Salatalık adım tanımını son parametre için bir tablo ile nasıl yeniden kullanırım?

Then %{I should see the following data in the "Feeds" data grid: 
                | Name | 
                | #{name} |} 

Ve bu:

Then "I should see the following data in the \"Feeds\" data grid: 
| Name | 
| #{name} |" 

Ve bu:

Then "I should see the following data in the \"Feeds\" data grid:\n| Name |\n| #{name} |" 

Ve hatta bu:

Then <<EOS 
I should see the following data in the "Feeds" data grid: 
| Name | 
| #{name} | 
EOS 

bana verir:

Your block takes 2 arguments, but the Regexp matched 1 argument. 
(Cucumber::ArityMismatchError) 
    tests/endtoend/step_definitions/instruments_editor_steps.rb:29:in `/^the editor shows "([^"]*)" in the feeds list$/' 
    melomel-0.6.0/lib/melomel/cucumber/data_grid_steps.rb:59:in `/^I should see the following data in the "([^"]*)" data grid:$/' 
    tests/endtoend/instruments_editor.feature:11:in `And the editor shows "myFeed" in the feeds list 

Bu seferki:

Then "I should see the following data in the \"Feeds\" data grid: | Name || #{name} |" 

Ve bu:

Then "I should see the following data in the \"Feeds\" data grid:| Name || #{name} |" 

verir:

Undefined step: "I should see the following data in the "Feeds" data grid:| Name || myFeed |" (Cucumber::Undefined) 
    ./tests/endtoend/step_definitions/instruments_editor_steps.rb:31:in `/^the editor shows "([^"]*)" in the feeds list$/' 
    tests/endtoend/instruments_editor.feature:11:in `And the editor shows "myFeed" in the feeds list' 

cevap

6

Ben cevabı buldum kendimi:

YUKARIDAKİ AÇIK 0
steps %Q{ 
Then I should see the following data in the "Feeds" data grid: 
               | Name | 
               | #{name} | 
} 
+0

gibi bir tablo alır, ama @kwon cevap iyi çalışıyor. .. – nodrog

3

NOT: bariz görünebilir, ancak yeni hat '{' ilk

bir başka yolu soooooo önemlidir sonra:

Given /^My basic step:$/ do |table| 
    #do table operation 
end 


Given /^My referring step:$/ do |table| 
    table.hashes.each do |row|  
    row_as_table = %{ 
     |prop1|prop2| 
     |#{row[:prop1]}|#{row[:prop2]}| 
    } 
    Given %{My basic step:}, Cucumber::Ast::Table.parse(row_as_table, "", 0) 
    end 
end 
3

Ayrıca kullanarak, bu şekilde yazabilirsiniz #table

Then /^some other step$/ do 
    Then %{I should see the following data in the "Feeds" data grid:}, table(%{ 
    | Name | 
    | #{name} | 
    }) 
end 
0

kullanmayı düşünün

Given /^events with:-$/ do |table| 
    Given %{I am on the event admin page} 
    table.hashes.each do |row| 
    Given %{an event with:-}, Cucumber::Ast::Table.new([row]).transpose 
    end 
end 

Tabloyu el ile oluşturarak çok daha zarif buluyorum.

olaylar ile: - Bu

| Form | Element | Label | 
| foo | bar  | baz | 

gibi bir tablo alır ve birlikte bir olay: - Bu çalışma alamadım

| Form | foo | 
| Element | bar | 
| Label | baz | 
İlgili konular