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.6.0 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.5.7 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-rails2-0.5.10 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-rails2-0.5.9 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-rails2-0.5.8 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-rails2-0.5.7 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-rails2-0.5.6 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.5.6 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.5.5 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.5.4 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.5.3 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.5.2 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.5.1 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.5.0 lib/couch_potato/rspec/matchers/map_to_matcher.rb
davber_couch_potato-0.4.0 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.4.0 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.3.2 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.3.1 lib/couch_potato/rspec/matchers/map_to_matcher.rb
davber_couch_potato-0.3.0 lib/couch_potato/rspec/matchers/map_to_matcher.rb
couch_potato-0.3.0 lib/couch_potato/rspec/matchers/map_to_matcher.rb