Skip to content

Instantly share code, notes, and snippets.

@haxney
Created August 18, 2011 01:52
Show Gist options
  • Save haxney/1153116 to your computer and use it in GitHub Desktop.
Save haxney/1153116 to your computer and use it in GitHub Desktop.
Rabl error in Rails specs
rails new rabl-test
rails generate scaffold task name:string
rails generate rspec:install
require 'spec_helper'
describe "tasks/index.json" do
before(:each) do
assign(:tasks, [
stub_model(Task,
:name => "Name"
),
stub_model(Task,
:name => "Name"
)
])
end
it "renders" do
render
rendered.should == %([{"task":{"name":"Name"}},{"task":{"name":"Name"}}])
end
end
class Task < ActiveRecord::Base
end
.F...
Failures:
1) tasks/index.json renders
Failure/Error: render
ActionView::MissingTemplate:
Missing template tasks/index.json with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :rabl], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:en, :en]} in view paths "/tmp/rabl-test/app/views"
# ./spec/views/tasks/index.rabl_spec.rb:17:in `block (2 levels) in <top (required)>'
Finished in 0.44473 seconds
5 examples, 1 failure
Failed examples:
rspec ./spec/views/tasks/index.rabl_spec.rb:16 # tasks/index.json renders
class TasksController < ApplicationController
respond_to :json, :xml, :html
# GET /tasks
# GET /tasks.xml
def index
@tasks = Task.all
respond_with(@tasks)
end
# GET /tasks/1
# GET /tasks/1.xml
def show
@task = Task.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @task }
end
end
# GET /tasks/new
# GET /tasks/new.xml
def new
@task = Task.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @task }
end
end
# GET /tasks/1/edit
def edit
@task = Task.find(params[:id])
end
# POST /tasks
# POST /tasks.xml
def create
@task = Task.new(params[:task])
respond_to do |format|
if @task.save
format.html { redirect_to(@task, :notice => 'Task was successfully created.') }
format.xml { render :xml => @task, :status => :created, :location => @task }
else
format.html { render :action => "new" }
format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
end
end
end
# PUT /tasks/1
# PUT /tasks/1.xml
def update
@task = Task.find(params[:id])
respond_to do |format|
if @task.update_attributes(params[:task])
format.html { redirect_to(@task, :notice => 'Task was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /tasks/1
# DELETE /tasks/1.xml
def destroy
@task = Task.find(params[:id])
@task.destroy
respond_to do |format|
format.html { redirect_to(tasks_url) }
format.xml { head :ok }
end
end
end
collection @tasks
attributes(:name, :id, :created_at, :updated_at)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment