Sha256: 910b580d07cb3050b8661eaa073de2beeff1fe07e6244389f2240c56b05c7766

Contents?: true

Size: 1.41 KB

Versions: 51

Compression:

Stored size: 1.41 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
      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:
      """ruby
      $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

51 entries across 51 versions & 13 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/features/helper_methods/let.feature
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/features/helper_methods/let.feature
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/features/helper_methods/let.feature
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/helper_methods/let.feature
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/helper_methods/let.feature
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/helper_methods/let.feature
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/helper_methods/let.feature
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/helper_methods/let.feature
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-core-2.14.8/features/helper_methods/let.feature
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-core-2.13.0/features/helper_methods/let.feature
rspec-core-2.99.2 features/helper_methods/let.feature
dxruby_rp5-0.0.4 spec/vendor/rspec-core-2.14.7/features/helper_methods/let.feature
rspec-core-2.99.1 features/helper_methods/let.feature
rspec-core-2.99.0 features/helper_methods/let.feature
rspec-core-2.99.0.rc1 features/helper_methods/let.feature
rspec-core-2.14.8 features/helper_methods/let.feature
rspec-core-2.99.0.beta2 features/helper_methods/let.feature
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-core-2.14.7/features/helper_methods/let.feature
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-core-2.14.7/features/helper_methods/let.feature
dxruby_rp5-0.0.3 spec/vendor/rspec-core-2.14.7/features/helper_methods/let.feature