Skip to content

Instantly share code, notes, and snippets.

@gmcinnes
Created January 21, 2009 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmcinnes/50033 to your computer and use it in GitHub Desktop.
Save gmcinnes/50033 to your computer and use it in GitHub Desktop.
require File.dirname(__FILE__) + '/../spec_helper'
# But uh oh, now all the tests look the same.
# We've factored it to the point where the code is hiding
# what the real intention is. Lets move the should_receive(:create_breadcrumb_list)
# stuff back into the it blocks so we can see the difference, and we
# should be done.
describe BreadcrumbsHelper do
describe '#add_breadcrumb' do
before(:each) do
@name = 'Test Name'
@url = 'http://testurl.com'
end
def mock_breadcrumb
mock = mock('Breadcrumb::Breadcrumb', :null_object => true)
Breadcrumb::Breadcrumb.should_receive(:new).with(@name, @url).and_return(mock)
return mock
end
describe ' when @_breadcrumb_list is nil' do
include BreadcrumbsHelper
before(:each) do
@_breadcrumb_list = nil
@_breadcrumb_list.should_receive(:<<).with(mock_breadcrumb)
end
it 'should call create_breadcrumb_list' do
self.should_receive(:create_breadcrumb_list)
add_breadcrumb(@name, @url)
end
it 'should add a Breadcrumb::Breadcrumb to the @_breadcrumb_list' do
self.should_receive(:create_breadcrumb_list)
add_breadcrumb(@name, @url)
end
end
describe ' when @_breadcrumb_list is not nil' do
include BreadcrumbsHelper
before(:each) do
@_breadcrumb_list = mock('Breadcrumb::List')
@_breadcrumb_list.should_receive(:<<).with(mock_breadcrumb)
end
it 'should not call #create_breadcrumb_list' do
self.should_not_receive(:create_breadcrumb_list)
add_breadcrumb(@name, @url)
end
it 'should add a breadcrumb to the @_breadcrumb_list' do
self.should_not_receive(:create_breadcrumb_list)
add_breadcrumb(@name, @url)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment