Created
November 2, 2011 17:15
-
-
Save denmarkin/1334262 to your computer and use it in GitHub Desktop.
Cucumber + Capybara HTML table comparison from http://railscasts.com/episodes/186-pickle-with-cucumber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then(/^I should see (.+) table$/) do |table_id, expected_table| | |
html_table = table_at("##{table_id.parameterize.tableize}").to_a | |
html_table.map! { |r| r.map! { |c| c.gsub(/<.+?>/, '').gsub(/[\n\t\r]/, '') } } | |
expected_table.diff!(html_table) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scenario: Adding a promo code | |
Given an administrator exists with email: "[email protected]", password: "testing" | |
And I am logged in as "[email protected]" with password "testing" | |
Given I am on path "/admin/promo_codes" | |
When I follow "+ Add code" | |
Then I should see "Create Promo Code" | |
When I fill in the following: | |
| Code | 50OFF | | |
| Percentage off | 50 | | |
And I select "2015-01-01" as the "Expire at" date | |
And I press "Create" | |
Then I should see "Promo Code '50OFF' has been added." | |
And I should see promo codes table | |
| Code | Expire at | Percentage off | Actions | | |
| 50OFF | January 01, 2015 00:00 | 50% | Delete | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HtmlSelectorsHelpers | |
#.... | |
def table_at(selector) # see https://gist.github.com/1149139 | |
Nokogiri::HTML(page.body).css(selector).map do |table| | |
table.css('tr').map do |tr| | |
tr.css('th, td').map { |td| td.text } | |
end | |
end[0].reject(&:empty?) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case this is useful to anyone, this is still in use, but needs some changes to be used in capybara 2.6.0