Sha256: c098d5442e2664c04003c72c5cf1c162b891063fe48d7667af5c12fec6c8cd69

Contents?: true

Size: 1.4 KB

Versions: 150

Compression:

Stored size: 1.4 KB

Contents

Feature: let and let!

  Use `let` to define a memoized helper method.  The value will be cached
  across multiple calls in the same example but not across examples.

  Note that `let` is lazy-evaluated: it is not evaluated until the first time
  the method it defines is invoked. You can use `let!` to force the method's
  invocation before each example.

  Scenario: use let to define memoized helper method
    Given a file named "let_spec.rb" with:
      """
      $count = 0
      describe "let" do
        let(:count) { $count += 1 }

        it "memoizes the value" do
          count.should eq(1)
          count.should eq(1)
        end

        it "is not cached across examples" do
          count.should eq(2)
        end
      end
      """
    When I run `rspec let_spec.rb`
    Then the examples should all pass

  Scenario: use let! to define a memoized helper method that is called in a before hook
    Given a file named "let_bang_spec.rb" with:
      """
      $count = 0
      describe "let!" do
        invocation_order = []

        let!(:count) do
          invocation_order << :let!
          $count += 1
        end

        it "calls the helper method in a before hook" do
          invocation_order << :example
          invocation_order.should == [:let!, :example]
          count.should eq(1)
        end
      end
      """
    When I run `rspec let_bang_spec.rb`
    Then the examples should all pass

Version data entries

150 entries across 95 versions & 14 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.9.0/features/helper_methods/let.feature
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.10.0/features/helper_methods/let.feature
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.9.0/features/helper_methods/let.feature
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.10.0/features/helper_methods/let.feature
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.10.0/features/helper_methods/let.feature
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.9.0/features/helper_methods/let.feature
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/features/helper_methods/let.feature
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/features/helper_methods/let.feature
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.10.0/features/helper_methods/let.feature
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.9.0/features/helper_methods/let.feature
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.9.0/features/helper_methods/let.feature
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.10.0/features/helper_methods/let.feature
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.10.0/features/helper_methods/let.feature
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.9.0/features/helper_methods/let.feature
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.10.1/features/helper_methods/let.feature
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.10.0/features/helper_methods/let.feature
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.9.0/features/helper_methods/let.feature
classiccms-0.6.8 vendor/bundle/gems/rspec-core-2.10.0/features/helper_methods/let.feature
classiccms-0.6.8 vendor/bundle/gems/rspec-core-2.9.0/features/helper_methods/let.feature
classiccms-0.6.7 vendor/bundle/gems/rspec-core-2.10.0/features/helper_methods/let.feature