Class: CouchPotato::RSpec::MapToMatcher
- Inherits:
-
Object
- Object
- CouchPotato::RSpec::MapToMatcher
- Includes:
- RSpec::Matchers::Composable
- Defined in:
- lib/couch_potato/rspec/matchers/map_to_matcher.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected_ruby, input_ruby) ⇒ MapToMatcher
constructor
A new instance of MapToMatcher.
- #matches?(view_spec) ⇒ Boolean
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 ⇒ Object
53 54 55 |
# File 'lib/couch_potato/rspec/matchers/map_to_matcher.rb', line 53 def "Expected to map to #{@expected_ruby.inspect} but got #{@actual_ruby.inspect}." end |
#failure_message_when_negated ⇒ Object
57 58 59 |
# File 'lib/couch_potato/rspec/matchers/map_to_matcher.rb', line 57 def "Expected not to map to #{@actual_ruby.inspect} but did." end |
#matches?(view_spec) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/couch_potato/rspec/matchers/map_to_matcher.rb', line 24 def matches?(view_spec) js = " (function() {\n var doc = \#{@input_ruby.to_json};\n var map = \#{view_spec.map_function};\n var result = [];\n var require = function(modulePath) {\n var module = {exports: {}};\n var exports = module.exports;\n var pathArray = modulePath.split(\"/\").slice(2);\n var result = {};\n for (var i in pathArray) {\n result = result[pathArray[i]];\n }\n eval(result);\n return module.exports;\n }\n\n var emit = function(key, value) {\n result.push([key, value]);\n };\n map(doc);\n return JSON.stringify(result);\n })()\n JS\n @actual_ruby = JSON.parse(ExecJS.eval(js))\n values_match? @expected_ruby, @actual_ruby\nend\n" |