transactional fixtures are enabled.
In spec/spec_helper.rb
config.use_transactional_fixtures = true
config.before(:all) { Sham.reset(:before_all) }
config.before(:each) { Sham.reset(:before_each) }
The following is the whole of comment_spec.rb, spec for comment model.
I have little knowledge about Rspec, Machinist and Testing. My code
must be strange, or crasy.
I would be happy, if you point out unordinal codes.
------------ comment_spec.rb -----------------
require File.dirname(__FILE__) + '/../spec_helper'
describe Comment, "with wrong fields" do
it "should not be valid" do
c = Comment.new
c.should_not be_valid
[:stars, :title, :body].each do |sym|
c.errors[sym].any?.should be_true
end
end
it "might have negative stars" do
c = Comment.make
c.stars = -1
c.should_not be_valid
end
it "might have too many stars" do
c = Comment.make
c.stars = 8
c.should_not be_valid
end
end
describe Comment, "with right fields" do
before do
@c = Comment.make
end
it "should be valid" do
@c.should be_valid
end
it "should have an book and user" do
@c.user.should be_instance_of User
@c.book.should be_instance_of Book
end
end
describe Comment, "with parent and children" do
before(:all) do
@child = Comment.make(:children)
end
it "should have the same book" do
@child.should be_valid
@child.book = Book.make
@child.should_not be_valid
end
it "should be exisiting parent" do
Comment.find(:all, :conditions => ['parent_comment IS
NULL']).count.should == 1
end
it "should be accessible via find" do
Comment.find(:first, :conditions => ['parent_comment == ?',
@child.parent_comment.id]).id.should == @child.id
end
end
------------ comment_spec.rb -----------------
--
Haruka YAGNI
--
Haruka YAGNI