Skip to content

Instantly share code, notes, and snippets.

@iHiD
Created June 26, 2011 18:31
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 iHiD/1047834 to your computer and use it in GitHub Desktop.
Save iHiD/1047834 to your computer and use it in GitHub Desktop.
Basic rspec example
#spec/models/product_spec.rb
require 'spec_helper'
describe Product do
before :each do
@valid_attributes = {name: "Test Product",
user: mock_model(User)}
end
describe "new records" do
it "should save with valid attributes" do
product = Product.create(@valid_attributes)
product.should_not be_new_record
end
it "must have a name" do
product = Product.new(@valid_attributes)
product.name = ""
product.valid?
product.errors.should include(:name)
end
it "name must be unique" do
Product.create!(@valid_attributes)
product = Product.new(@valid_attributes)
product.valid?
product.errors.should include(:name)
end
end
describe "saved records" do
before :each do
@product = Product.create(@valid_attributes)
end
it "test something with a product"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment