Sha256: 040bac4dd79ec1d149e8cf7a77d72ef5d4d14324823044b501988073d2ed8c9d

Contents?: true

Size: 1.25 KB

Versions: 47

Compression:

Stored size: 1.25 KB

Contents

# https://rspec.lighthouseapp.com/projects/16211/tickets/305
require 'singleton'

module NegativeExpectationsHelper

  class State
    include Singleton

    def is_negative?
      @negative === true
    end

    def is_negative!
      @negative = true
    end

    def restore!
      @negative = false
    end
  end

  module ObjectExpectations
    def self.included(base)
      base.class_eval do
        alias_method :original_should, :should
        alias_method :original_should_not, :should_not

        def should(*args, &block)
          should_if_true(!State.instance.is_negative?, *args, &block)
        end

        def should_not(*args, &block)
          should_if_true(State.instance.is_negative?, *args, &block)
        end
      end
    end

    private # ----------------------------------------------------------------

    def should_if_true(cond, *args, &block)
      cond ? self.send(:original_should, *args, &block) : self.send(:original_should_not, *args, &block)
    end
  end

  def expect_opposite_if(cond)
    raise "expected block" unless block_given?
    State.instance.is_negative! if cond
    yield
    State.instance.restore! if cond
  end
end

class Object
  include NegativeExpectationsHelper::ObjectExpectations
end

World(NegativeExpectationsHelper)

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
refinerycms-testing-1.0.11 features/support/negative_expectations_helper.rb
refinerycms-testing-1.0.10 features/support/negative_expectations_helper.rb
refinerycms-testing-1.0.9 features/support/negative_expectations_helper.rb
refinerycms-testing-1.0.8 features/support/negative_expectations_helper.rb
refinerycms-testing-1.0.7 features/support/negative_expectations_helper.rb
refinerycms-testing-1.0.5 features/support/negative_expectations_helper.rb
refinerycms-testing-1.0.4 features/support/negative_expectations_helper.rb
refinerycms-testing-1.0.3 features/support/negative_expectations_helper.rb
refinerycms-testing-1.0.1 features/support/negative_expectations_helper.rb
refinerycms-testing-1.0.0 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.22 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.21 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.20 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.19 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.18 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.17 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.16 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.15 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.14 features/support/negative_expectations_helper.rb
refinerycms-testing-0.9.9.13 features/support/negative_expectations_helper.rb