Skip to content

Instantly share code, notes, and snippets.

@mrnugget
Created January 3, 2012 17:05
Show Gist options
  • Save mrnugget/1555817 to your computer and use it in GitHub Desktop.
Save mrnugget/1555817 to your computer and use it in GitHub Desktop.
## song_tag_spec.rb
describe SongTag do
before(:each) do
@song = Song.create(:file_name => "01.testing.mp3")
@tag = Tag.new(:name => "great")
@song_tag = @song.song_tags.build(:tag_id => @tag.id)
end
it "should create a new instance given valid attributes" do
@song_tag.save!
end
describe "validations" do
it "should require a song_id" do
@song_tag.song_id = nil
@song_tag.should_not be_valid
end
it "should require a tag_id" do
@song_tag.tag_id = nil
@song_tag.should_not be_valid
end
end
describe "song and tag methods" do
it "should have a song attribute" do
@song_tag.should respond_to(:song)
end
it "should have the right song" do
@song_tag.song.should == @song
end
it "should have a tag attribute" do
@song_tag.should respond_to(:tag)
end
it "should have the right tag" do
@song_tag.tag.should == @tag
end
end
end
## rspec spec/
..........F.....F..............................
Failures:
1) SongTag should create a new instance given valid attributes
Failure/Error: @song_tag.save!
ActiveRecord::RecordInvalid:
Validation failed: Tag can't be blank
# ./spec/models/song_tag_spec.rb:13:in `block (2 levels) in <top (required)>'
2) SongTag song and tag methods should have the right tag
Failure/Error: @song_tag.tag.should == @tag
expected: #<Tag id: nil, name: "great", created_at: nil, updated_at: nil>
got: nil (using ==)
# ./spec/models/song_tag_spec.rb:44:in `block (3 levels) in <top (required)>'
Finished in 21.14 seconds
47 examples, 2 failures
Failed examples:
rspec ./spec/models/song_tag_spec.rb:12 # SongTag should create a new instance given valid attributes
rspec ./spec/models/song_tag_spec.rb:43 # SongTag song and tag methods should have the right tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment