Sha256: d57504ce4bceb975b6469a5f82a93ffa2cac52f836659954f57a1ddd68140157

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

module CouchPotato
  module RSpec
    class ListAsProxy
      def initialize(results_ruby)
        @results_ruby = results_ruby
      end

      def as(expected_ruby)
        ListAsMatcher.new(expected_ruby, @results_ruby)
      end
    end

    class ListAsMatcher
      include RunJS

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

      def matches?(view_spec)
        js = <<-JS
          #{File.read(File.dirname(__FILE__) + '/json2.js')}
          var results = #{@results_ruby.to_json};
          var listed = '';
          var list = #{view_spec.list_function};

          var getRow = function() {
            return results.rows.shift();
          };
          var send = function(text) {
            listed = listed + text;
          };
          list();
          JSON.stringify(JSON.parse(listed));
        JS

        @actual_ruby = JSON.parse(run_js(js))

        @expected_ruby == @actual_ruby
      end

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

      def failure_message_for_should_not
        "Expected to not list as #{@expected_ruby.inspect} but did."
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
couch_potato-1.4.0 lib/couch_potato/rspec/matchers/list_as_matcher.rb
couch_potato-1.3.0 lib/couch_potato/rspec/matchers/list_as_matcher.rb
couch_potato-1.2.0 lib/couch_potato/rspec/matchers/list_as_matcher.rb
couch_potato-1.1.4 lib/couch_potato/rspec/matchers/list_as_matcher.rb
couch_potato-1.1.2 lib/couch_potato/rspec/matchers/list_as_matcher.rb
couch_potato-1.1.1 lib/couch_potato/rspec/matchers/list_as_matcher.rb
couch_potato-1.1.0 lib/couch_potato/rspec/matchers/list_as_matcher.rb
couch_potato-1.0.1 lib/couch_potato/rspec/matchers/list_as_matcher.rb
couch_potato-1.0.0 lib/couch_potato/rspec/matchers/list_as_matcher.rb