Created
October 5, 2011 13:41
-
-
Save nickhoffman/1264453 to your computer and use it in GitHub Desktop.
Stubbing with Cells
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductHaveCell < Cell::Rails | |
def description(have) | |
condition = have.condition | |
desc = "#{have.quantity}x #{condition.name}" | |
if have.sealed | |
desc += ' ' + I18n.t('words.Sealed').downcase | |
elsif have.packaging | |
desc += ' ' + I18n.t('phrases.product_haves.with_packaging') | |
end | |
if have.price_paid > 0 | |
desc += " for $#{have.price_paid}" | |
end | |
unless have.obtained_from.blank? | |
desc += " #{I18n.t 'words.from'} #{have.obtained_from}" | |
end | |
render :text => desc | |
end | |
def description_link(have) | |
desc = description have | |
render :locals => {:have => have, :description => desc} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ be rspec spec/cells/product_have_cell_spec.rb | |
Run filtered using {:focus=>true} | |
F | |
Failures: | |
1) ProductHaveCell#description_link generates a description for the product have | |
Failure/Error: render_cell :product_have, :description_link, @have do |cell| | |
Mock "ProductHave_1001" received unexpected message :condition with (no args) | |
# ./app/cells/product_have_cell.rb:3:in `description' | |
# ./app/cells/product_have_cell.rb:24:in `description_link' | |
# ./spec/cells/product_have_cell_spec.rb:10:in `block (3 levels) in <top (required)>' | |
Finished in 0.33534 seconds | |
1 example, 1 failure | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe ProductHaveCell do | |
describe '#description_link', :focus => true do | |
before :each do | |
@have = mock_model ProductHave | |
end | |
it 'generates a description for the product have' do | |
render_cell :product_have, :description_link, @have do |cell| | |
cell.stub(:description).with(any_args).and_return 'some description' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment