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



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

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

#failure_message_for_should_notObject



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

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
42
# File 'lib/couch_potato/rspec/matchers/list_as_matcher.rb', line 21

def matches?(view_spec)
  js = <<-JS
    #{File.read(File.dirname(__FILE__) + '/print_r.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();
    print(print_r(JSON.parse(listed)));
  JS
  
  @actual_ruby = JSON.parse(run_js(js))
  
  @expected_ruby == @actual_ruby
end