Skip to content

Instantly share code, notes, and snippets.

@paulca
Created January 15, 2011 12:56
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 paulca/780891 to your computer and use it in GitHub Desktop.
Save paulca/780891 to your computer and use it in GitHub Desktop.
refactoring using let, subject and its
require 'spec_helper'
describe EasonBook do
describe ".load!" do
let(:house_at_riverton_item) { Item.find_by_barcode(9780330448444) }
let(:house_at_riverton) { EasonBook.find(9780330448444) }
before(:each) do
# set a category mapping
CategoryMapping.create!({:system_name => 'eason',
:system_code => "FAZ",
:category_id => 1})
# loading EASONWWW.TXT from data_feed/test/today/eason/
EasonBook.load!
end
describe "loaded book" do
subject { house_at_riverton }
it { should_not be_nil }
its(:title) { should == "House at Riverton" }
its(:author) { should == "Morton Kate"}
end
describe "loaded item" do
subject { house_at_riverton_item }
it { should have(1).category_memberships }
it "should set up category memberships" do
house_at_riverton_item.category_memberships.first.category_id.should == 1
end
end
it "should load the items table" do
Item.count.should == 14
end
end
end
require 'spec_helper'
describe EasonBook do
describe ".load!" do
let(:house_at_riverton_item) { Item.find_by_barcode(9780330448444) }
let(:house_at_riverton) { EasonBook.find(9780330448444) }
before(:each) do
# set a category mapping
CategoryMapping.create!({:system_name => 'eason',
:system_code => "FAZ",
:category_id => 1})
# loading EASONWWW.TXT from data_feed/test/today/eason/
EasonBook.load!
end
it "should load the eason_books table" do
house_at_riverton.should_not be_nil
end
it "should set the title" do
house_at_riverton.title.should == "House at Riverton"
end
it "should set the title" do
house_at_riverton.author.should == "Morton Kate"
end
it "should load the items table" do
Item.count.should == 14
end
it "should set up category memberships" do
house_at_riverton_item.should have(1).category_memberships
house_at_riverton_item.category_memberships.first.category_id.should == 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment