Sha256: 1dd9b0da981411e3ba863bba722a4b1e96b8852a77d10b01776395e103c6810e

Contents?: true

Size: 1.44 KB

Versions: 7

Compression:

Stored size: 1.44 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:
      """ruby
      $count = 0
      RSpec.describe "let" do
        let(:count) { $count += 1 }

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

        it "is not cached across examples" do
          expect(count).to 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:
      """ruby
      $count = 0
      RSpec.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
          expect(invocation_order).to eq([:let!, :example])
          expect(count).to eq(1)
        end
      end
      """
    When I run `rspec let_bang_spec.rb`
    Then the examples should all pass

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
opal-rspec-0.8.0 rspec-core/upstream/features/helper_methods/let.feature
opal-rspec-0.8.0.alpha3 rspec-core/upstream/features/helper_methods/let.feature
opal-rspec-0.8.0.alpha2 rspec-core/upstream/features/helper_methods/let.feature
opal-rspec-0.8.0.alpha1 rspec-core/upstream/features/helper_methods/let.feature
opal-rspec-0.7.1 rspec-core/upstream/features/helper_methods/let.feature
opal-rspec-0.7.0 rspec-core/upstream/features/helper_methods/let.feature
opal-rspec-0.7.0.rc.2 rspec-core/upstream/features/helper_methods/let.feature