Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stubbing with Cells
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
$ 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
$
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