Sha256: 7f1e7f770063b9f00a1fc2249e0aa9e5dc7b8c5c26ce2504bbba76fcb2883799

Contents?: true

Size: 691 Bytes

Versions: 44

Compression:

Stored size: 691 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

  it "generates an instance method" do
    counter.count.should == 1
  end

  it "caches the value" do
    counter.count.should == 1
    counter.count.should == 2
  end
end

describe "#let!" do
  let!(:creator) do
    class Creator
      @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 == 1
  end
end

Version data entries

44 entries across 44 versions & 4 rubygems

Version Path
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/rspec-core-2.5.1/spec/rspec/core/let_spec.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/rspec-core-2.5.1/spec/rspec/core/let_spec.rb
rspec-core-2.6.4 spec/rspec/core/let_spec.rb
rspec-core-2.6.3 spec/rspec/core/let_spec.rb
rspec-core-2.6.3.beta1 spec/rspec/core/let_spec.rb
rspec-core-2.6.2.rc spec/rspec/core/let_spec.rb
rspec-core-2.6.0 spec/rspec/core/let_spec.rb
rspec-core-2.6.0.rc6 spec/rspec/core/let_spec.rb
rspec-core-2.5.2 spec/rspec/core/let_spec.rb
rspec-core-2.6.0.rc4 spec/rspec/core/let_spec.rb
rspec-core-2.6.0.rc2 spec/rspec/core/let_spec.rb
rspec-core-2.5.1 spec/rspec/core/let_spec.rb
rspec-core-2.5.0 spec/rspec/core/let_spec.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/rspec/core/let_spec.rb
rspec-core-2.4.0 spec/rspec/core/let_spec.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/rspec/core/let_spec.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/rspec/core/let_spec.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/rspec-core-2.1.0/spec/rspec/core/let_spec.rb
rspec-core-2.3.1 spec/rspec/core/let_spec.rb
rspec-core-2.3.0 spec/rspec/core/let_spec.rb