07 Aug 2012, 18:50
Generic-user-small

Kevin Lau (2 posts)

Hi, I finished Matt’s tutorial a while ago and starting this tutorial. I am used to using Rspec and I was wondering if there was any way to convert the test from pdf page 98 to rspec.

this is what I have so far, just playing around

require ‘spec_helper’

describe ProductsController do render_views

before(:each) do
end
@product = Product.new
@update= (:product)
@attr = {
  :title         => 'pickachu',
  :description   => 'warm and yellow',
  :image_url     => 'lorem.jpeg',
  :price         =>  2.99
}
it "should get index" do
  get :index
  assert_response :success
  assert_not_nil assigns(:products)
end
it "should get new" do
  get :new
  assert_response :success
end
it "should create product" do
  assert_difference('Product.count') do
    post :create, :product => @attr
end
response.should redirected_to (product_path(assigns(:product)))
end
it "should  destroy a product" do
      lambda do
        post :create, :id => @attr
      end.should change(Product, :count).by(1)
end
it "should redirect to the products show page" do
      post :create, :product => @attr
      response.should redirect_to(product_path(assigns(:product)))
end
it "should update product" do
  put :update, :id => @update, :product => @attr
  response.should redirect_to(product_path(assigns(:product)))
end
it "should  destroy a product" do
      lambda do
        delete :destroy, :product => @update
      end.should_not change(Product, :count).by(-1)
end
end

I know my test is a mess as I was trying different things to get it to work. Thank you.

08 Aug 2012, 17:49
Generic-user-small

Kevin Lau (2 posts)

Figured it out myself.

Thank you if any of you are reading this!

  You must be logged in to comment