spreewald 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/spreewald/table_steps.rb +22 -7
- data/lib/spreewald_support/version.rb +1 -1
- metadata +3 -3
@@ -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
|
-
|
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
|
-
|
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,
|
119
|
+
tables.should_not contain_table(parsed_table, options)
|
105
120
|
else
|
106
|
-
tables.should contain_table(parsed_table,
|
121
|
+
tables.should contain_table(parsed_table, options)
|
107
122
|
end
|
108
123
|
end
|
109
124
|
end
|
metadata
CHANGED