Sha256: 45ce2f8a4198148c960114f82c6ebc7c9f5c0502cacdbdd45a924362f7638ab6

Contents?: true

Size: 1.19 KB

Versions: 39

Compression:

Stored size: 1.19 KB

Contents

require 'json'


module CouchPotato
  module RSpec
    class MapToProxy
      def initialize(input_ruby)
        @input_ruby = input_ruby
      end
      
      def to(*expected_ruby)
        MapToMatcher.new(expected_ruby, @input_ruby)
      end
    end
    
    class MapToMatcher
      include RunJS
      
      def initialize(expected_ruby, input_ruby)
        @expected_ruby = expected_ruby
        @input_ruby = input_ruby
      end
      
      def matches?(view_spec)
        js = <<-JS
          #{File.read(File.dirname(__FILE__) + '/print_r.js')}
          var doc = #{@input_ruby.to_json};
          var map = #{view_spec.map_function};
          var result = [];
          var emit = function(key, value) {
            result.push([key, value]);
          };
          map(doc);
          print(print_r(result));
        JS
        @actual_ruby = JSON.parse(run_js(js))
        @expected_ruby == @actual_ruby
      end
      
      def failure_message_for_should
        "Expected to map to #{@expected_ruby.inspect} but got #{@actual_ruby.inspect}."
      end
      
      def failure_message_for_should_not
        "Expected not to map to #{@actual_ruby.inspect} but did."
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 3 rubygems

Version Path
couch_potato-0.2.32 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.31 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.30 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.29 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.28 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.27 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.26 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.25 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.24 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.23 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.22 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.21 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.20 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.19 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.18 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.17 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.16 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.15 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.2.14 lib/couch_potato/rspec/matchers/map_to_matcher.rb