Class: CouchPotato::RSpec::ListAsMatcher
- Inherits:
-
Object
- Object
- CouchPotato::RSpec::ListAsMatcher
- Defined in:
- lib/couch_potato/rspec/matchers/list_as_matcher.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected_ruby, results_ruby) ⇒ ListAsMatcher
constructor
A new instance of ListAsMatcher.
- #matches?(view_spec) ⇒ Boolean
Constructor Details
#initialize(expected_ruby, results_ruby) ⇒ ListAsMatcher
Returns a new instance of ListAsMatcher.
14 15 16 17 |
# File 'lib/couch_potato/rspec/matchers/list_as_matcher.rb', line 14 def initialize(expected_ruby, results_ruby) @expected_ruby = expected_ruby @results_ruby = results_ruby end |
Instance Method Details
#failure_message ⇒ Object
42 43 44 |
# File 'lib/couch_potato/rspec/matchers/list_as_matcher.rb', line 42 def "Expected to list as #{@expected_ruby.inspect} but got #{@actual_ruby.inspect}." end |
#failure_message_when_negated ⇒ Object
46 47 48 |
# File 'lib/couch_potato/rspec/matchers/list_as_matcher.rb', line 46 def "Expected to not list as #{@expected_ruby.inspect} but did." end |
#matches?(view_spec) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/couch_potato/rspec/matchers/list_as_matcher.rb', line 19 def matches?(view_spec) js = <<-JS (function() { var results = #{@results_ruby.to_json}; var listed = ''; var list = #{view_spec.list_function}; var getRow = function() { return results.rows.shift(); }; var send = function(text) { listed = listed + text; }; list(); return JSON.stringify(JSON.parse(listed)); })() JS @actual_ruby = JSON.parse(ExecJS.eval(js)) @expected_ruby == @actual_ruby end |