manage_froobles.feature -------------------------------------- Scenario: Delete frooble Given the following froobles: |name|color|description| |name 1|color 1|description 1| |name 2|color 2|description 2| |name 3|color 3|description 3| |name 4|color 4|description 4| When I delete the 3rd frooble Then I should see the following froobles: |name|color|description| |name 1|color 1|description 1| |name 2|color 2|description 2| |name 4|color 4|description 4| ---------------------------------------------------------------------------------------------------------------- froobles_steps.rb -------------------------------------- When /^I delete the (\d+)(?:st|nd|rd|th) frooble$/ do |pos| visit froobles_url within("table > tr:nth-child(#{pos.to_i+1})") do click_link "Destroy" end end Then /^I should see the following froobles:$/ do |froobles| froobles.raw[1..-1].each_with_index do |row, i| row.each_with_index do |cell, j| response.should have_selector("table > tr:nth-child(#{i+2}) > td:nth-child(#{j+1})") { |td| td.inner_text.should == cell } end end end I want to show a definition list instead of a table. index.html -------------------------------------- <dl> <dt>description 1</dt> <dd>show | edit| destroy</dd> <dt>description 2</dt> <dd>show | edit| destroy</dd> </dl> so I''m trying manage_froobles.feature -------------------------------------- Scenario: Delete frooble Given the following froobles: |description| |description 1| |description 2| |description 3| |description 4| When I delete the 3rd frooble Then I should see the following froobles: |description| |description 1| |description 2| |description 4| ---------------------------------------------------------------------------------------------------------------- froobles_steps.rb -------------------------------------- When /^I delete the (\d+)(?:st|nd|rd|th) frooble$/ do |pos| visit froobles_url within("dl:nth-child(#{pos.to_i})") do click_link "Destroy" end end (this passes but I really don''t know if it''s "clicking" the destroy link on the third list item.) Then /^I should see the following froobles:$/ do |froobles| tasks.raw[1..-1].each_with_index do |row, i| response.should have_selector("dl:nth-child(#{i+3})") { |td| td.inner_text.should == row } end end (this fails) I can follow the logic of the table but for some reason I can''t write this test for a list. Any help would be appreciated. John
aslak hellesoy
2009-Feb-26 15:59 UTC
[rspec-users] [cucumber] noob Q deleteing from a list.
On Thu, Feb 26, 2009 at 12:03 AM, John Ivanoff <john.ivanoff at gmail.com> wrote:> manage_froobles.feature > -------------------------------------- > ?Scenario: Delete frooble > ? ?Given the following froobles: > ? ? ?|name|color|description| > ? ? ?|name 1|color 1|description 1| > ? ? ?|name 2|color 2|description 2| > ? ? ?|name 3|color 3|description 3| > ? ? ?|name 4|color 4|description 4| > ? ?When I delete the 3rd frooble > ? ?Then I should see the following froobles: > ? ? ?|name|color|description| > ? ? ?|name 1|color 1|description 1| > ? ? ?|name 2|color 2|description 2| > ? ? ?|name 4|color 4|description 4| > > ---------------------------------------------------------------------------------------------------------------- > froobles_steps.rb > -------------------------------------- > When /^I delete the (\d+)(?:st|nd|rd|th) frooble$/ do |pos| > ?visit froobles_url > ?within("table > tr:nth-child(#{pos.to_i+1})") do > ? ?click_link "Destroy" > ?end > end > > Then /^I should see the following froobles:$/ do |froobles| > ?froobles.raw[1..-1].each_with_index do |row, i| > ? ?row.each_with_index do |cell, j| > ? ? ?response.should have_selector("table > tr:nth-child(#{i+2}) > > td:nth-child(#{j+1})") { |td| > ? ? ? ?td.inner_text.should == cell > ? ? ?} > ? ?end > ?end > end > > I want to show a definition list instead of a table. > > index.html > -------------------------------------- > <dl> > ?<dt>description 1</dt> > ?<dd>show | edit| destroy</dd> > ?<dt>description 2</dt> > ?<dd>show | edit| destroy</dd> > </dl> > > so I''m trying > manage_froobles.feature > -------------------------------------- > ?Scenario: Delete frooble > ? ?Given the following froobles: > ? ? ?|description| > ? ? ?|description 1| > ? ? ?|description 2| > ? ? ?|description 3| > ? ? ?|description 4| > ? ?When I delete the 3rd frooble > ? ?Then I should see the following froobles: > ? ? ?|description| > ? ? ?|description 1| > ? ? ?|description 2| > ? ? ?|description 4| > > ---------------------------------------------------------------------------------------------------------------- > froobles_steps.rb > -------------------------------------- > When /^I delete the (\d+)(?:st|nd|rd|th) frooble$/ do |pos| > ?visit froobles_url > ?within("dl:nth-child(#{pos.to_i})") do > ? ?click_link "Destroy" > ?end > end > (this passes but I really don''t know if it''s "clicking" the destroy > link on the third list item.) >3 possibilities: 1) It''s clicking the right link, but your next page renders wrong 2) It''s clicking the right link, but your next page renders correctly, but your Then is buggy 3) It''s not clicking the right link In order to find out which one it is...> Then /^I should see the following froobles:$/ do |froobles|# Do this here: puts response.body Aslak> ?tasks.raw[1..-1].each_with_index do |row, i| > ? ?response.should have_selector("dl:nth-child(#{i+3})") { |td| > ? ? ?td.inner_text.should == row > ? ?} > ?end > end > (this fails) > > I can follow the logic of the table but for some reason I can''t write > this test for a list. > > Any help would be appreciated. > > John > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Thu, Feb 26, 2009 at 7:59 AM, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:> puts response.bodyAnother debugging technique we use is When /^I view the response$/ do Tempfile.open("response") do |file| file.print response.body `open "file://#{file.path}"` sleep 2 end end ///ark
Mark Wilden wrote:> On Thu, Feb 26, 2009 at 7:59 AM, aslak hellesoy > <aslak.hellesoy at gmail.com> wrote: > > >> puts response.body >> > > Another debugging technique we use is > > When /^I view the response$/ do > Tempfile.open("response") do |file| > file.print response.body > `open "file://#{file.path}"` > sleep 2 > end > end > > ///ark > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >If you are using webrat and you want to see the HTML repsonse you can use: save_and_open_page -Ben
Thanks for all the help. With the puts response.body I was able so see what was going on. I know that I am now deleting the third frooble!!!! Now when Then I should see the following froobles: I get this error ---------------------------------- Then I should see the following froobles: # features/step_definitions/ frooble_steps.rb:12 expected: ["description 1"], got: "description 1" (using ==) Diff: @@ -1,2 +1,2 @@ -["description 1"] +"description 1" (Spec::Expectations::ExpectationNotMetError) ./features/step_definitions/frooble_steps.rb:18:in `Then /^I should see the following froobles:$/'' /Library/Ruby/Gems/1.8/gems/webrat-0.4.0/lib/webrat/core/ matchers/have_xpath.rb:50:in `call'' /Library/Ruby/Gems/1.8/gems/webrat-0.4.0/lib/webrat/core/ matchers/have_xpath.rb:50:in `matches_nokogiri?'' /Library/Ruby/Gems/1.8/gems/webrat-0.4.0/lib/webrat/core/ matchers/have_xpath.rb:15:in `matches?'' ./features/step_definitions/frooble_steps.rb:17:in `Then /^I should see the following froobles:$/'' (eval):3:in `each_with_index'' ./features/step_definitions/frooble_steps.rb:16:in `each'' ./features/step_definitions/frooble_steps.rb:16:in `each_with_index'' ./features/step_definitions/frooble_steps.rb:16:in `Then /^I should see the following froobles:$/'' features/list.feature:15:in `Then I should see the following froobles:'' ---------------------------------- Again any help will be appreciated. John On Feb 26, 1:08?pm, Ben Mabey <b... at benmabey.com> wrote:> Mark Wilden wrote: > > On Thu, Feb 26, 2009 at 7:59 AM, aslak hellesoy > > <aslak.helle... at gmail.com> wrote: > > >> puts response.body > > > Another debugging technique we use is > > > When /^I view the response$/ do > > ? Tempfile.open("response") do |file| > > ? ? file.print response.body > > ? ? `open "file://#{file.path}"` > > ? ? sleep 2 > > ? end > > end > > > ///ark > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > If you are using webrat and you want to see the HTML repsonse you can > use: save_and_open_page > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
John Ivanoff wrote:> Thanks for all the help. With the > puts response.body > I was able so see what was going on. I know that I am now deleting the > third frooble!!!! > > Now when > Then I should see the following froobles: > I get this error > ---------------------------------- > Then I should see the following froobles: # features/step_definitions/ > frooble_steps.rb:12 > expected: ["description 1"], > got: "description 1" (using ==) > Diff: > @@ -1,2 +1,2 @@ > -["description 1"] > +"description 1" (Spec::Expectations::ExpectationNotMetError) > ./features/step_definitions/frooble_steps.rb:18:in `Then /^I > should see the following froobles:$/'' > /Library/Ruby/Gems/1.8/gems/webrat-0.4.0/lib/webrat/core/ > matchers/have_xpath.rb:50:in `call'' > /Library/Ruby/Gems/1.8/gems/webrat-0.4.0/lib/webrat/core/ > matchers/have_xpath.rb:50:in `matches_nokogiri?'' > /Library/Ruby/Gems/1.8/gems/webrat-0.4.0/lib/webrat/core/ > matchers/have_xpath.rb:15:in `matches?'' > ./features/step_definitions/frooble_steps.rb:17:in `Then /^I > should see the following froobles:$/'' > (eval):3:in `each_with_index'' > ./features/step_definitions/frooble_steps.rb:16:in `each'' > ./features/step_definitions/frooble_steps.rb:16:in > `each_with_index'' > ./features/step_definitions/frooble_steps.rb:16:in `Then /^I > should see the following froobles:$/'' > features/list.feature:15:in `Then I should see the following > froobles:'' > ---------------------------------- > > Again any help will be appreciated. >You are expecting a list in your test but you are getting back a string.> John > > On Feb 26, 1:08 pm, Ben Mabey <b... at benmabey.com> wrote: > >> Mark Wilden wrote: >> >>> On Thu, Feb 26, 2009 at 7:59 AM, aslak hellesoy >>> <aslak.helle... at gmail.com> wrote: >>> >>>> puts response.body >>>> >>> Another debugging technique we use is >>> >>> When /^I view the response$/ do >>> Tempfile.open("response") do |file| >>> file.print response.body >>> `open "file://#{file.path}"` >>> sleep 2 >>> end >>> end >>> >>> ///ark >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> If you are using webrat and you want to see the HTML repsonse you can >> use: save_and_open_page >> >> -Ben >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > >-- Joseph Wilk http://blog.josephwilk.net