Sam Treweek
2009-Oct-02 16:16 UTC
[rspec-users] Running a specific row in cucumber example table
I want to be able to execute only 1 row in an Scenario/Outline Example table. Is there a method already created for me to access. I have certain validation rules for only running 1 row of data coming from an external request to execute cuke. So having something in a step_definition file like: test.rb If $something table.row.skip end Before do pending end etc... -- Posted via http://www.ruby-forum.com/.
Matt Wynne
2009-Oct-02 16:21 UTC
[rspec-users] Running a specific row in cucumber example table
On 2 Oct 2009, at 17:16, Sam Treweek wrote:> I want to be able to execute only 1 row in an Scenario/Outline Example > table. Is there a method already created for me to access. I have > certain validation rules for only running 1 row of data coming from an > external request to execute cuke. > > So having something in a step_definition file like: > > test.rb > > If $something > table.row.skip > end > > Before do > pending > endI have no idea if this will work, but you could try to sense for the table row you want to skip in a Before block, then call skip_invoke! on it: Before(scenario_or_example_row) do if the_one_to_skip?(scenario_or_example_row) scenario_or_example_row.skip_invoke! end end That might work for you, but you should be aware that #skip_invoke! is not part of the public API right now and might be changed without warning. Obviously you''ll have to write #the_one_to_skip? method yourself... It would probably be better to be able to tag the example table row, and just filter it out before the feature run. We can''t do that right now can we?> > etc... > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-userscheers, Matt http://mattwynne.net +447974 430184
David Chelimsky
2009-Oct-02 16:27 UTC
[rspec-users] Running a specific row in cucumber example table
On Fri, Oct 2, 2009 at 11:16 AM, Sam Treweek <lists at ruby-forum.com> wrote:> I want to be able to execute only 1 row in an Scenario/Outline Example > table. Is there a method already created for me to access. I have > certain validation rules for only running 1 row of data coming from an > external request to execute cuke. > > So having something in a step_definition file like: > > test.rb > > If $something > ? table.row.skip > end > > Before do > ?pending > end > > etc... > --Please direct cucumber questions to http://groups.google.com/group/cukes
Zoltan Penzeli
2009-Oct-05 08:49 UTC
[rspec-users] Running a specific row in cucumber example table
> I have no idea if this will work, but you could try to sense for the > table row you want to skip in a Before block, then call skip_invoke! > on it: > > Before(scenario_or_example_row) do > if the_one_to_skip?(scenario_or_example_row) > scenario_or_example_row.skip_invoke! > end > end >Well, this isn''t really working (or I might forgot something to define, but from http://wiki.github.com/aslakhellesoy/cucumber/hooks - it seems that ''Before'' is operating with tags (and hooks) - see This is in fact be useful, because we are able execute code before each line of the properly tagged Scenario Outline... but... I still don''t know the method/variable to access the _current line_ of the example table. So translated into the code, an example: x.feature: ... @tagged Scenario Outline: file reader Given I read <file> Then I want to have <content> Examples: | file | content | | x.txt | Text | | y.txt | Other text | *************************** step_definitions/x.rb Before(''@tagged'') do # how to access current row??? if row[0] == $external_filename # how to properly skip current line??? row.skip_invoke! end end Given /I read (.+)/ do |fileName| #open and read fileName #fill @file_content end Then /I want to have (.+)/ do |content| #assert ''content'' against @file_content end ********************************** So we need something for ''row[0]'' and a proper way to skip the current line... I now that this example is not a good real life situation (it would be easier to use multiline step arguments), but we would like to use Cucumber driven by an external source (executing only one line from each example table) AND maintaining the ability to run it independently (all lines) I hope this cleared up the things a bit more... Thanks for your ideas! -- Posted via http://www.ruby-forum.com/.
Matt Wynne
2009-Oct-05 11:03 UTC
[rspec-users] Running a specific row in cucumber example table
On 5 Oct 2009, at 09:49, Zoltan Penzeli wrote:> >> I have no idea if this will work, but you could try to sense for the >> table row you want to skip in a Before block, then call skip_invoke! >> on it: >> >> Before(scenario_or_example_row) do >> if the_one_to_skip?(scenario_or_example_row) >> scenario_or_example_row.skip_invoke! >> end >> endSorry, my example is bollocks. Try this instead: Before do |scenario_or_example_row| if the_one_to_skip?(scenario_or_example_row) scenario_or_example_row.skip_invoke! end end So the thing yielded to the Before block is the Scenario object if you''re in a Scenario, or the OutlineTable::ExampleRow if you''re in an outline table. You can call skip_invoke! on either of those objects to tell them not to invoke their step definition.>> > > Well, this isn''t really working (or I might forgot something to > define, > but from http://wiki.github.com/aslakhellesoy/cucumber/hooks - it > seems > that ''Before'' is operating with tags (and hooks) - see > > This is in fact be useful, because we are able execute code before > each > line of the properly tagged Scenario Outline... but... I still don''t > know the method/variable to access the _current line_ of the example > table. > > So translated into the code, an example: > > x.feature: > ... > @tagged > Scenario Outline: file reader > Given I read <file> > Then I want to have <content> > > Examples: > | file | content | > | x.txt | Text | > | y.txt | Other text | > > *************************** > step_definitions/x.rb > > Before(''@tagged'') do > # how to access current row??? > if row[0] == $external_filename > # how to properly skip current line??? > row.skip_invoke! > end > end > > Given /I read (.+)/ do |fileName| > #open and read fileName > #fill @file_content > end > > Then /I want to have (.+)/ do |content| > #assert ''content'' against @file_content > end > > ********************************** > > So we need something for ''row[0]'' and a proper way to skip the current > line... > > I now that this example is not a good real life situation (it would be > easier to use multiline step arguments), but we would like to use > Cucumber driven by an external source (executing only one line from > each > example table) AND maintaining the ability to run it independently > (all > lines) > > I hope this cleared up the things a bit more... > > Thanks for your ideas! > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-userscheers, Matt http://mattwynne.net +447974 430184