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 = "    \#{File.read(File.dirname(__FILE__) + '/print_r.js')}\n    \#{File.read(File.dirname(__FILE__) + '/json2.js')}\n    var results = \#{@results_ruby.to_json};\n    var listed = '';\n    var list = \#{view_spec.list_function};\n    \n    var getRow = function() {\n      return results.rows.shift();\n    };\n    var send = function(text) {\n      listed = listed + text;\n    };\n    list();\n    print(print_r(JSON.parse(listed)));\n  JS\n  \n  @actual_ruby = JSON.parse(run_js(js))\n  \n  @expected_ruby == @actual_ruby\nend\n"