This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| # Thanks to Henning Koch: https://makandracards.com/makandra/763-cucumber-step-to-match-table-rows-with-capybara | |
| module ArrayMethods | |
| def find_row(expected_row) | |
| find_index do |row| | |
| expected_row.all? do |expected_column| | |
| first_column = row.find_index do |column| | |
| content = column.content.gsub(/[\r\n\t]+/, ' ').gsub(/[ ]+/, ' ').strip | |
| expected_content = expected_column.gsub(' ', ' ').strip | |
| matching_parts = expected_content.split('*', -1).collect { |part| Regexp.escape(part) } | |
| matching_expression = /\A#{matching_parts.join(".*")}\z/ |
| class CardCreator < Struct.new(:listener) | |
| def create(iteration, attributes) | |
| card = iteration.cards.build(attributes) | |
| if card.save | |
| listener.created(card) | |
| else | |
| listener.create_failed(card) | |
| end | |
| end | |
| end |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer