small medium large xlarge

Generic-user-small
07 Aug 2012, 18:50
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

@product = Product.new
@update= (:product)
@attr = {
  :title         => 'pickachu',
  :description   => 'warm and yellow',
  :image_url     => 'lorem.jpeg',
  :price         =>  2.99
}   end

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.

Generic-user-small
08 Aug 2012, 17:49
Kevin Lau (2 posts)

Figured it out myself.

Thank you if any of you are reading this!

You must be logged in to comment