Module: Kronk::Test::Assertions
- Included in:
- Kronk::Test
- Defined in:
- lib/kronk/test/assertions.rb
Instance Method Summary collapse
-
#assert_data_at(data, path, msg = nil) ⇒ Object
Assert that the given path exists in data.
-
#assert_data_at_equal(data, path, match, msg = nil) ⇒ Object
Assert that at least one data point found with the given path is equal to the given match.
-
#assert_data_at_not_equal(data, path, match, msg = nil) ⇒ Object
Assert that no data points found with the given path are equal to the given match.
-
#assert_equal_responses(uri1, uri2, options = {}) ⇒ Object
Makes request to both uris and asserts that the parsed data they return is equal.
-
#assert_no_data_at(data, path, msg = nil) ⇒ Object
Assert that the given path doesn’t exist in data.
Instance Method Details
#assert_data_at(data, path, msg = nil) ⇒ Object
Assert that the given path exists in data. Supports all DataSet#find_data path types.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/kronk/test/assertions.rb', line 11 def assert_data_at data, path, msg=nil msg ||= "No data found at #{path.inspect} for #{data.inspect}" found = false Path.find path, data do |d,k,p| found = true break end assert found, msg end |
#assert_data_at_equal(data, path, match, msg = nil) ⇒ Object
Assert that at least one data point found with the given path is equal to the given match. Supports all DataSet#find_data path types.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kronk/test/assertions.rb', line 46 def assert_data_at_equal data, path, match, msg=nil last_data = nil found = false Path.find path, data do |d,k,p| found = true last_data = d[k] break if d[k] == match end assert found, msg || "No data found at #{path.inspect} for #{data.inspect}" assert_equal match, last_data, msg end |
#assert_data_at_not_equal(data, path, match, msg = nil) ⇒ Object
Assert that no data points found with the given path are equal to the given match. Supports all DataSet#find_data path types.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/kronk/test/assertions.rb', line 68 def assert_data_at_not_equal data, path, match, msg=nil last_data = nil Path.find path, data do |d,k,p| last_data = d[k] break if d[k] == match end assert_not_equal match, last_data, msg end |
#assert_equal_responses(uri1, uri2, options = {}) ⇒ Object
Makes request to both uris and asserts that the parsed data they return is equal. Compares response body if data is unparsable. Supports all options of Kronk.compare.
85 86 87 88 89 90 |
# File 'lib/kronk/test/assertions.rb', line 85 def assert_equal_responses uri1, uri2, ={} resp1 = Kronk.request(uri1, ).stringify resp2 = Kronk.request(uri2, ).stringify assert_equal resp1, resp2 end |
#assert_no_data_at(data, path, msg = nil) ⇒ Object
Assert that the given path doesn’t exist in data. Supports all DataSet#find_data path types.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kronk/test/assertions.rb', line 28 def assert_no_data_at data, path, msg=nil msg ||= "Data found at #{path.inspect} for #{data.inspect}" found = false Path.find path, data do |d,k,p| found = true break end assert !found, msg end |