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
templater-0.3.2 lib/templater/spec/helpers.rb
templater-0.3.0 lib/templater/spec/helpers.rb
templater-0.3.4 lib/templater/spec/helpers.rb
templater-0.3.1 lib/templater/spec/helpers.rb
templater-0.2.2 lib/templater/spec/helpers.rb
templater-0.4.2 lib/templater/spec/helpers.rb
templater-0.4.0 lib/templater/spec/helpers.rb
templater-0.4.3 lib/templater/spec/helpers.rb
templater-0.4.4 lib/templater/spec/helpers.rb
templater-0.5.0 lib/templater/spec/helpers.rb
templater-0.4.1 lib/templater/spec/helpers.rb
templater-0.4.5 lib/templater/spec/helpers.rb
templater-0.3.5 lib/templater/spec/helpers.rb