Created
June 26, 2011 18:31
-
-
Save iHiD/1047834 to your computer and use it in GitHub Desktop.
Basic rspec example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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