spreewald 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,11 +42,13 @@ module TableStepsHelper
42
42
  rspec::Matchers.define :contain_table do |*args|
43
43
  match do |tables|
44
44
  @last_unmatched_row = nil
45
+ @extra_rows = nil
45
46
  @best_rows_matched = -1
46
- expected_table, unordered = args
47
+ options = args.extract_options!
48
+ expected_table = args.first
47
49
  tables.any? do |table|
48
50
  rows_matched = 0
49
- expected_table.all? do |expected_row|
51
+ match = expected_table.all? do |expected_row|
50
52
  if @best_rows_matched < rows_matched
51
53
  @last_unmatched_row = expected_row
52
54
  @best_rows_matched = rows_matched
@@ -57,7 +59,7 @@ module TableStepsHelper
57
59
  false
58
60
  else
59
61
  rows_matched += 1
60
- if unordered
62
+ if options[:unordered]
61
63
  table.delete_at(first_row)
62
64
  else
63
65
  table = table[(first_row + 1)..-1]
@@ -65,11 +67,22 @@ module TableStepsHelper
65
67
  true
66
68
  end
67
69
  end
70
+ if match and options[:exactly] and not table.empty?
71
+ @extra_rows = table
72
+ match = false
73
+ end
74
+ match
68
75
  end
69
76
  end
70
77
 
71
78
  failure_message_for_should do
72
- "Could not find the following row: #{@last_unmatched_row.inspect}"
79
+ if @extra_rows
80
+ "Found the following extra row: #{@extra_rows.first.collect(&:content).collect(&:squish).inspect}"
81
+ elsif @last_unmatched_row
82
+ "Could not find the following row: #{@last_unmatched_row.inspect}"
83
+ else
84
+ "Could not find a table"
85
+ end
73
86
  end
74
87
 
75
88
  failure_message_for_should_not do
@@ -94,16 +107,18 @@ end
94
107
  World(TableStepsHelper)
95
108
 
96
109
 
97
- Then /^I should( not)? see a table with the following rows( in any order)?:?$/ do |negate, unordered, expected_table|
110
+ Then /^I should( not)? see a table with (exactly )?the following rows( in any order)?:?$/ do |negate, exactly, unordered, expected_table|
98
111
  patiently do
99
112
  document = Nokogiri::HTML(page.body)
100
113
  tables = document.xpath('//table').collect { |table| table.xpath('.//tr').collect { |row| row.xpath('.//th|td') } }
101
114
  parsed_table = parse_table(expected_table)
102
115
 
116
+ options = { :exactly => exactly, :unordered => unordered }
117
+
103
118
  if negate
104
- tables.should_not contain_table(parsed_table, unordered)
119
+ tables.should_not contain_table(parsed_table, options)
105
120
  else
106
- tables.should contain_table(parsed_table, unordered)
121
+ tables.should contain_table(parsed_table, options)
107
122
  end
108
123
  end
109
124
  end
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module Spreewald
4
- VERSION = "0.4.4"
4
+ VERSION = "0.4.5"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreewald
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 4
10
- version: 0.4.4
9
+ - 5
10
+ version: 0.4.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Kraze