Class: CouchPotato::RSpec::ListAsMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/couch_potato/rspec/matchers/list_as_matcher.rb

Instance Method Summary collapse

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_messageObject



42
43
44
# File 'lib/couch_potato/rspec/matchers/list_as_matcher.rb', line 42

def failure_message
  "Expected to list as #{@expected_ruby.inspect} but got #{@actual_ruby.inspect}."
end

#failure_message_when_negatedObject



46
47
48
# File 'lib/couch_potato/rspec/matchers/list_as_matcher.rb', line 46

def failure_message_when_negated
  "Expected to not list as #{@expected_ruby.inspect} but did."
end

#matches?(view_spec) ⇒ Boolean

Returns:

  • (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