Sha256: b98c5b401bf055cfdfc188de7e95b09be56ed72554a2630a0673fe048a0bc896

Contents?: true

Size: 890 Bytes

Versions: 5

Compression:

Stored size: 890 Bytes

Contents

class Shoulda::Context
  def execute(&execute_block)
    setup do
      @execute_block = execute_block
    end
  end

  alias :should_without_execute :should

  def should(name = nil, options = {}, &block)
    if block.nil?
      should_without_execute(name, options)
    else
      should_without_execute(name, options) do
        if @execute_block
          self.instance_variable_set('@execute_result', Shoulda::Context.shoulda_execute_call_block(self, @execute_block))
        end
        Shoulda::Context.shoulda_execute_call_block(self, block)
      end
    end
  end
  
  def self.shoulda_execute_call_block(test, block)
    if should_execute_shared_should_available?
      test.call_block_with_shared_value(block)
    else
      block.bind(test).call
    end
  end
  
  def self.should_execute_shared_should_available?
    Test::Unit::TestCase.respond_to? :share_context
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
always_execute-0.1.3 lib/shoulda_execute.rb
always_execute-0.1.2 lib/shoulda_execute.rb
always_execute-0.1.1 lib/shoulda_execute.rb
always_execute-0.1.0 lib/shoulda_execute.rb
always_execute-0.0.2 lib/shoulda_execute.rb