Skip to content

Instantly share code, notes, and snippets.

@data-doge
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save data-doge/ba5eee622410ef2eb477 to your computer and use it in GitHub Desktop.

Select an option

Save data-doge/ba5eee622410ef2eb477 to your computer and use it in GitHub Desktop.
FactoryGirl.define do
factory :cat do
name Faker::Name.name
life_story Faker::Lorem.paragraph
image_url Faker::Avatar.image
factory :cat_with_1_life do
lives 1
end
end
end
class CatsController < ApplicationController
def index
@cats = Cat.all
end
def show
@cat = Cat.find(params(:id))
end
end
require 'rails_helper'
RSpec.describe CatsController, type: :controller do
describe "#index" do
before do
5.times { Cat.create(attributes_for(:cat)) }
get :index
end
it { should respond_with(200) }
it { should render_template(:index) }
it "should assign @cats to all Cats in DB" do
expect(assigns(:cats)).to eq(Cat.all)
end
end
describe "#show" do
before do
@cat = Cat.create(attributes_for(:cat))
get :show, id: @cat.id
end
it { should respond_with(200) }
it { should render_template(:show) }
it "should assign cat with specified id to @cat" do
expect(assigns(:cat)).to eq(@cat)
end
end
end
Failures:
1) CatsController#show
Failure/Error: get :show, :id => @cat.id
ArgumentError:
wrong number of arguments (1 for 0)
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/metal/strong_parameters.rb:656:in `params'
# ./app/controllers/cats_controller.rb:8:in `show'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/abstract_controller/base.rb:198:in `process_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:117:in `call'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:117:in `call'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `block in halting'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `call'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `block in halting'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `call'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `_run_callbacks'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/abstract_controller/callbacks.rb:19:in `process_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:164:in `block in instrument'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:164:in `instrument'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/abstract_controller/base.rb:137:in `process'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionview-4.2.0/lib/action_view/rendering.rb:30:in `process'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/test_case.rb:629:in `process'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/test_case.rb:65:in `process'
# /Users/eugenelynch/.rvm/gems/ruby-2.2.0@global/gems/actionpack-4.2.0/lib/action_controller/test_case.rb:505:in `get'
# ./spec/controllers/cats_controller_spec.rb:24:in `block (3 levels) in <top (required)>'
Rails.application.routes.draw do
resources :cats
root to: 'cats#index'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment