Sha256: b10f8b50a27c9bf253a6aae1c67e6cce90de688157aacb5bf16f62a4214e3377

Contents?: true

Size: 1.17 KB

Versions: 13

Compression:

Stored size: 1.17 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper.rb'

class Substance
  def initialize exists, description
    @exists = exists
    @description = description
  end
  def exist?
    @exists
  end
  def inspect
    @description
  end
end
  
class SubstanceTester
  include Spec::Matchers
  def initialize substance
    @substance = substance
  end
  def should_exist
    @substance.should exist
  end
end

describe "should exist" do
  
  before(:each) do
    @real = Substance.new true, 'something real'
    @imaginary = Substance.new false, 'something imaginary'
  end

  describe "within an example group" do
  
    it "passes if target exists" do
      @real.should exist
    end
  
    it "fails if target does not exist" do
      lambda { @imaginary.should exist }.should fail
    end
    
    it "describes itself" do
      exist.description.should == "exists"
    end
    
    it "passes should_not exist if target doesn't exist" do
      lambda { @real.should_not exist }.should fail
    end
  end

  describe "outside of an example group" do

    it "should pass if target exists" do
      real_tester = SubstanceTester.new @real
      real_tester.should_exist
    end

  end

end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
dchelimsky-rspec-1.1.99.1 spec/spec/matchers/exist_spec.rb
dchelimsky-rspec-1.1.99.13 spec/spec/matchers/exist_spec.rb
dchelimsky-rspec-1.1.99.2 spec/spec/matchers/exist_spec.rb
dchelimsky-rspec-1.1.99.3 spec/spec/matchers/exist_spec.rb
dchelimsky-rspec-1.1.99.4 spec/spec/matchers/exist_spec.rb
dchelimsky-rspec-1.1.99.5 spec/spec/matchers/exist_spec.rb
dchelimsky-rspec-1.1.99.6 spec/spec/matchers/exist_spec.rb
dchelimsky-rspec-1.1.99.7 spec/spec/matchers/exist_spec.rb
dchelimsky-rspec-1.1.99.8 spec/spec/matchers/exist_spec.rb
dchelimsky-rspec-1.1.99.9 spec/spec/matchers/exist_spec.rb
rspec-1.2.2 spec/spec/matchers/exist_spec.rb
rspec-1.2.1 spec/spec/matchers/exist_spec.rb
rspec-1.2.0 spec/spec/matchers/exist_spec.rb