Sha256: 3d169f67f99ff91037bef127330b77834fb8b9e84eeea569e4b66ff8e40f9f07

Contents?: true

Size: 880 Bytes

Versions: 155

Compression:

Stored size: 880 Bytes

Contents

require 'spec_helper'

describe "#let" do
  let(:counter) do
    Class.new do
      def initialize
        @count = 0
      end
      def count
        @count += 1
      end
    end.new
  end

  let(:nil_value) do
    @nil_value_count += 1
    nil
  end

  it "generates an instance method" do
    counter.count.should eq(1)
  end

  it "caches the value" do
    counter.count.should eq(1)
    counter.count.should eq(2)
  end

  it "caches a nil value" do
    @nil_value_count = 0
    nil_value
    nil_value

    @nil_value_count.should eq(1)
  end
end

describe "#let!" do
  let!(:creator) do
    Class.new do
      @count = 0
      def self.count
        @count += 1
      end
    end
  end

  it "evaluates the value non-lazily" do
    lambda { creator.count }.should_not raise_error
  end

  it "does not interfere between tests" do
    creator.count.should eq(1)
  end
end

Version data entries

155 entries across 100 versions & 15 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.10.0/spec/rspec/core/let_spec.rb
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.9.0/spec/rspec/core/let_spec.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.10.0/spec/rspec/core/let_spec.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.9.0/spec/rspec/core/let_spec.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.10.0/spec/rspec/core/let_spec.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.9.0/spec/rspec/core/let_spec.rb
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/spec/rspec/core/let_spec.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/spec/rspec/core/let_spec.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.9.0/spec/rspec/core/let_spec.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.10.0/spec/rspec/core/let_spec.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.10.0/spec/rspec/core/let_spec.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.9.0/spec/rspec/core/let_spec.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.10.0/spec/rspec/core/let_spec.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.9.0/spec/rspec/core/let_spec.rb
remq-0.0.4 vendor/bundle/gems/rspec-core-2.12.2/spec/rspec/core/let_spec.rb
remq-0.0.3 vendor/bundle/gems/rspec-core-2.12.2/spec/rspec/core/let_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.10.1/spec/rspec/core/let_spec.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.10.0/spec/rspec/core/let_spec.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.9.0/spec/rspec/core/let_spec.rb
rspec-core-2.12.2 spec/rspec/core/let_spec.rb