Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 db
Octocat-spinner-32 doc
Octocat-spinner-32 lib
Octocat-spinner-32 public
Octocat-spinner-32 script
Octocat-spinner-32 spec
Octocat-spinner-32 vendor
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 README
Octocat-spinner-32 Rakefile
Octocat-spinner-32 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.