Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app
config
db
doc
lib/tasks
public
script
spec
vendor/plugins
.gitignore
Gemfile
Gemfile.lock
README
Rakefile
config.ru

README

We have this situation

require 'spec_helper'

class Foo
  attr_accessor :name
  def initialize(*args)
    super
    self.name = 'foolish'
  end
end

class Bar < Foo
  attr_accessor :bars  
  def initialize(*args)
    super
    self.name = 'barish'
  end
end

class FooBar
  attr_accessor :bars  
  def initialize(*args)
    super
    self.bars = [Bar.new, Foo.new]
  end
  
  def bars_bar
    self.bars.each { |x| puts x.class }
    self.bars.detect{ |x| x.class == Bar }
  end
end


require 'spec_helper'

describe FooBar do
  describe 'situation 1' do
    before do
      @foo_mock = mock
      @foo_mock.stub(:name){'foo mock'}
      Foo.should_receive(:new){@foo_mock}
      @bar_mock = mock
      @bar_mock.stub(:name){'bar mock'}
      Bar.should_receive(:new){@bar_mock}
      @test_object = FooBar.new
    end
    it { @test_object.bars.should be_include(@foo_mock) }
    it { @test_object.bars.should be_include(@bar_mock) }
  end
  describe 'situation 2' do
    before do
      @test_object = FooBar.new
    end
    it { @test_object.bars_bar.name.should == 'barish' }
    it { Bar.new.name.should == 'barish' }
  end
end
Something went wrong with that request. Please try again.