Class: CouchPotato::RSpec::MapToMatcher

Inherits:
Object
  • Object
show all
Includes:
RunJS
Defined in:
lib/couch_potato/rspec/matchers/map_to_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_ruby, input_ruby) ⇒ MapToMatcher

Returns a new instance of MapToMatcher.



19
20
21
22
# File 'lib/couch_potato/rspec/matchers/map_to_matcher.rb', line 19

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

Instance Method Details

#failure_message_for_shouldObject



40
41
42
# File 'lib/couch_potato/rspec/matchers/map_to_matcher.rb', line 40

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

#failure_message_for_should_notObject



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

def failure_message_for_should_not
  "Expected not to map to #{@actual_ruby.inspect} but did."
end

#matches?(view_spec) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/couch_potato/rspec/matchers/map_to_matcher.rb', line 24

def matches?(view_spec)
  js = "    \#{File.read(File.dirname(__FILE__) + '/print_r.js')}\n    var doc = \#{@input_ruby.to_json};\n    var map = \#{view_spec.map_function};\n    var result = [];\n    var emit = function(key, value) {\n      result.push([key, value]);\n    };\n    map(doc);\n    print(print_r(result));\n  JS\n  @actual_ruby = JSON.parse(run_js(js))\n  @expected_ruby == @actual_ruby\nend\n"