I am trying to write a test case for the depot application. Below is the code
Model:
class Product < ActiveRecord::Base
attr_accessible :description, :image_url, :price, :title
validates :title, :description, :image_url, :presence => true
validates :price, :numericality => {:greater_than_or_equal_to => 0.01}
end
Test Case:
require 'spec_helper'
describe Product do
before :each do
@product = Product.new "Title", "Description", "Image Url", "Price"
end
describe "#new" do
it "takes four parameters and returns a product" do
@product.should be_an_instance_of Product
end
end
describe "#title" do
it "returns the correct title" do
@product.title.should eql "Title"
end
end
describe "#description" do
it "returns the correct description" do
@product.description.should eql "Description"
end
end
describe "#image_url" do
it "returns the correct image_url" do
@product.image_url.should eql "Image Url"
end
end
describe "#price" do
it "returns the correct price" do
@product.price.should eql "Price"
end
end
end
I am getting the errors
undefined method `has_key?' for nil:NilClass
and
ArgumentError:←[0m
1mwrong number of arguments (4 for 2)←[0m
./spec/product_spec.rb:5:in `new'←[0m
./spec/product_spec.rb:5:in `block (2 levels) \
in <top (required)>'" for all examples.
Please guide me on how to correct it
Try something like this:
Try Michael Hartl’s awesome tutorial