Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A simple let for shoulda
branch: master

v0.0.6

latest commit 0285c477c0
Michael Grosser authored
Failed to load latest commit information.
gemfiles fix travis
lib/shoulda support MiniTest
test make test more explicit
.travis.yml fix travis
Appraisals fix travis
Gemfile fix travis
Gemfile.lock v0.0.6
Rakefile fix travis
Readme.md
shoulda-let.gemspec v0.0.6

Readme.md

A simple let for shoulda

Install

gem install shoulda-let

# Gemfile
gem "shoulda-let", :require => "shoulda/let"

Usage

context "let" do
  let(:thing){ "a thing" }

  should "make the result available via let" do
    assert_equal 'a thing', let(:thing)
  end

  should 'make the result available via an instance method' do
    assert_equal 'a thing', thing
  end

  context "memoization" do
    let(:thing) do
      @invocations ||= 0
      @invocations += 1
      rand
    end

    should "be stable" do
      first_value = thing
      assert_equal first_value, thing
      assert_equal first_value, let(:thing)
    end

    should 'not reevaluate' do
      thing; thing; thing
      assert_equal 1, @invocations
    end
  end

  context "a child context with an overridden let" do
    let(:thing) { 'child thing' }

    should "use the overridden value" do
      assert_equal "child thing", thing
    end
  end

  context 'a child context with no overridden let' do
    should 'use the parent value' do
      assert_equal 'a thing', thing
    end
  end

  context "let!" do
    let!(:thing) do
      @thing_instantiated = true
      'anything'
    end

    should "automatically be evaluated" do
      assert @thing_instantiated
    end

    should 'otherwise work like let' do
      assert_equal 'anything', thing
    end
  end

  context 'evaluation context' do
    let(:thing) do
      @let_evaluation_context = self
      'a thing'
    end

    should 'be the test case' do
      thing
      assert_equal self, @let_evaluation_context
    end
  end
end

Author

Contributors

Michael Grosser
michael@grosser.it
License: MIT
Build Status

Something went wrong with that request. Please try again.