Browse files

Updated README code formatting.

  • Loading branch information...
1 parent 8372732 commit d0681c970da1d9bda98bc5962474c4796268b8d1 @panthomakos committed May 18, 2011
Showing with 26 additions and 26 deletions.
  1. +26 −26 README.markdown
View
52 README.markdown
@@ -12,15 +12,15 @@ Create a sham file for each of your models:
# in sham/user_sham.rb
class User::Sham
- def self.options
- { :name => "Sample User" }
- end
+ def self.options
+ { :name => "Sample User" }
+ end
end
To enable Sham in a particular environment, add the following to your environment.rb or test.rb file:
config.after_initialize do
- Sham::Config.activate!
+ Sham::Config.activate!
end
To enable Sham in cucumber, add the following to your features/support/env.rb file:
@@ -45,27 +45,27 @@ Here is an example of testing validations on an ActiveRecord::Base class using S
# in app/models/item.rb
class Item < ActiveRecord::Base
- validates_numericality_of :quantity, :greater_than => 0
+ validates_numericality_of :quantity, :greater_than => 0
end
# in sham/item_sham.rb
class Item::Sham
- def self.options
- { :quantity => 1 }
- end
+ def self.options
+ { :quantity => 1 }
+ end
end
# in spec/models/item_spec.rb
describe Item do
- it "should not allow items with a negative price" do
- item = Item.sham! :build, :quantity => -1
- item.valid?.should be_false
- end
-
- it "should allow items with a positive quantity" do
- item = Item.sham! :build, :quantity => 10
- item.valid?.should be_true
- end
+ it "should not allow items with a negative price" do
+ item = Item.sham! :build, :quantity => -1
+ item.valid?.should be_false
+ end
+
+ it "should allow items with a positive quantity" do
+ item = Item.sham! :build, :quantity => 10
+ item.valid?.should be_true
+ end
end
## Shamming Alternatives
@@ -74,13 +74,13 @@ You can add other alternative variations to the default "sham!" functionality:
# in sham/item_sham.rb
class Item::Sham
- def self.options
- { :weight => 1.0 }
- end
+ def self.options
+ { :weight => 1.0 }
+ end
- def self.large_options
- { :weight => 100.0 }
- end
+ def self.large_options
+ { :weight => 100.0 }
+ end
end
These can be invoked using:
@@ -94,9 +94,9 @@ You can nest shammed models inside others:
# in sham/line_item_sham.rb
class LineItem::Sham
- def self.options
- { :item => Sham::Base.new(Item) }
- end
+ def self.options
+ { :item => Sham::Base.new(Item) }
+ end
end
The nested shams will automatically be invoked and can be overridden during a sham:

0 comments on commit d0681c9

Please sign in to comment.