Sha256: c2d7138953714fd86628beddea23bf356e1beb7f844c2f8904abac09400e611f

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'test/unit'
require 'test/unit/given'

class TestSimpleGiven < Test::Unit::Given::TestCase

  def test_basics
    Given {
      @x = nil
    }
    When {
      @x = 4
    }
    Then {
      assert_equal 4,@x
    }
  end

  def test_cannot_use_locals
    Given {
      @x = nil
    }
    When {
      x = 4
    }
    Then {
      assert_nil @x
      refute defined? x
    }
  end

  def test_can_reuse_blocks
    invocations = 0
    x_is_nil = Given {
      @x = nil
      invocations += 1
    }
    x_is_assigned_to_four = When {
      @x = 4
      invocations += 1
    }
    x_should_be_four = Then {
      assert_equal 4,@x
      invocations += 1
    }
    Given x_is_nil
    When x_is_assigned_to_four
    Then x_should_be_four
    assert_equal 6,invocations
  end

  def test_methods_that_return_blocks
    Given a_nil_x
    When {
      @x = 4
    }
    Then {
      assert_equal 4,@x
    }
  end

  def test_invert_for_block_based_asserts
    Given a_nil_x
    Then {
      assert_raises NoMethodError do
        When {
          @x + 4
        }
      end
    }
  end

  private 

  def a_nil_x
    Proc.new { @x = nil }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
test_unit-given-0.0.1 test/test_simple_given.rb