Skip to content

Instantly share code, notes, and snippets.

@novohispano
Created January 30, 2014 23:17
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 novohispano/8722223 to your computer and use it in GitHub Desktop.
Save novohispano/8722223 to your computer and use it in GitHub Desktop.
Example of Model Testing
require 'spec_helper'
describe Item do
it "should exist" do
item = Item.new
expect item
end
it "should have a name" do
item = Item.new(name: "hammer")
expect item.name.should eq "hammer"
end
it "should have a description" do
item = Item.new(description: "long")
expect item.description.should eq "long"
end
it "should not be valid without a name" do
item = Item.new(description: "short")
expect(item).not_to be_valid
end
it "should not be valid without a description" do
item = Item.new(name: "ball")
expect(item).not_to be_valid
end
it "should not create and item if the name exists" do
item1 = Item.create(name: "ball", description: "round")
item2 = Item.create(name: "ball", description: "red")
expect(item2).not_to be_valid
end
it "should have orders" do
item = Item.new
expect item.orders
end
it "should have order items" do
item = Item.new
expect item.order_items
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment