Sha256: b39baa2bae5dc7af38f0c5596eb1c5f31f78deac1c86c8375ba700754d6914f7

Contents?: true

Size: 1.69 KB

Versions: 33

Compression:

Stored size: 1.69 KB

Contents

module Templater
  module Spec
    module Helpers

      class InvokeMatcher
        def initialize(expected)
          @expected = expected
        end

        def matches?(actual)
          @actual = actual
          # Satisfy expectation here. Return false or raise an error if it's not met.
          found = nil
          @actual.invocations.each { |i| found = i if i.class == @expected }

          if @with
            return found && (@with == found.arguments)
          else
            return found
          end
        end

        def with(*arguments)
          @with = arguments
          return self
        end

        def failure_message
          "expected #{@actual.inspect} to invoke #{@expected.inspect} with #{@with}, but it didn't"
        end

        def negative_failure_message
          "expected #{@actual.inspect} not to invoke #{@expected.inspect} with #{@with}, but it did"
        end
      end

      def invoke(expected)
        InvokeMatcher.new(expected)
      end

      class CreateMatcher
        def initialize(expected)
          @expected = expected
        end

        def matches?(actual)
          @actual = actual
          # Satisfy expectation here. Return false or raise an error if it's not met.
          @actual.all_actions.map{|t| t.destination }.include?(@expected)
        end

        def failure_message
          "expected #{@actual.inspect} to create #{@expected.inspect}, but it didn't"
        end

        def negative_failure_message
          "expected #{@actual.inspect} not to create #{@expected.inspect}, but it did"
        end
      end

      def create(expected)
        CreateMatcher.new(expected)
      end

    end # Helpers
  end # Spec
end # Templater

Version data entries

33 entries across 32 versions & 3 rubygems

Version Path
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/templater-1.0.0/lib/templater/spec/helpers.rb
ginst-2009.12.8 vendor/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/templater-1.0.0/lib/templater/spec/helpers.rb
ginst-2009.11.24 vendor/gems/templater-1.0.0/lib/templater/spec/helpers.rb
ginst-2009.11.23 vendor/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.10.17 vendor/gems/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.10.16 vendor/gems/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.10.15 vendor/gems/gems/templater-1.0.0/lib/templater/spec/helpers.rb
middleman-0.10.14 vendor/gems/gems/templater-1.0.0/lib/templater/spec/helpers.rb
ginst-2.0.1 vendor/gems/templater-1.0.0/lib/templater/spec/helpers.rb
ginst-2.0.0 vendor/gems/templater-1.0.0/lib/templater/spec/helpers.rb
templater-1.0.0 lib/templater/spec/helpers.rb
templater-0.2.1 lib/templater/spec/helpers.rb
templater-0.3.3 lib/templater/spec/helpers.rb
templater-0.2 lib/templater/spec/helpers.rb