Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created March 4, 2011 19:23
Show Gist options
  • Save JakubOboza/855526 to your computer and use it in GitHub Desktop.
Save JakubOboza/855526 to your computer and use it in GitHub Desktop.
first some tests....
require 'spec_helper'
describe CatsController do
describe "#index" do
it "should display cats" do
get :index
response.status.should eql(200)
end
end
describe "#create" do
it "should create new cat" do
lambda do
post :create, :cat => {:name => "test-hitler-looking-cat", :url => "http://lolcat.com/test.png"}
response.status.should eql(302)
end.should change(Cat, :count).by(1)
end
end
end
# new route in config/routes.rb
resources :cats
# some controller code
class CatsController < ApplicationController
def index
@cats = Cat.all
end
def create
@cat = Cat.new(params[:cat])
if @cat.save
redirect_to cats_path
else
render :action => :index
end
end
end
Pending:
Application should earn loads of money
# Not Yet Implemented
# ./spec/application_spec.rb:6
Finished in 0.10377 seconds
5 examples, 0 failures, 1 pending
Failures:
1) CatsController#index should display cats
Failure/Error: get :index
ActionController::RoutingError:
No route matches {:controller=>"cats"}
# ./spec/controllers/cats_controller_spec.rb:7
2) CatsController#create should create new cat
Failure/Error: post :create, :cat => {:name => "test-hitler-looking-cat", :url => "http://lolcat.com/test.png"}
ActionController::RoutingError:
No route matches {:cat=>{:url=>"http://lolcat.com/test.png", :name=>"test-hitler-looking-cat"}, :action=>"create", :controller=>"cats"}
# ./spec/controllers/cats_controller_spec.rb:15
# ./spec/controllers/cats_controller_spec.rb:14
Finished in 0.11783 seconds
6 examples, 2 failures, 2 pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment