Class: CouchPotato::RSpec::ListAsMatcher

Inherits:
Object
  • Object
show all
Includes:
RunJS
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.



16
17
18
19
# File 'lib/couch_potato/rspec/matchers/list_as_matcher.rb', line 16

def initialize(expected_ruby, results_ruby)
  @expected_ruby = expected_ruby
  @results_ruby = results_ruby
end

Instance Method Details

#failure_message_for_shouldObject



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

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

#failure_message_for_should_notObject



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

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

#matches?(view_spec) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/couch_potato/rspec/matchers/list_as_matcher.rb', line 21

def matches?(view_spec)
  js = <<-JS
    #{File.read(File.dirname(__FILE__) + '/json2.js')}
    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();
    JSON.stringify(JSON.parse(listed));
  JS

  @actual_ruby = JSON.parse(run_js(js))

  @expected_ruby == @actual_ruby
end