Skip to content

Instantly share code, notes, and snippets.

class Animal
def initialize(legs)
@legs = legs
end
def legs_in_animal
@legs
end
end
def upcase(text):
return text.upper()
@upcase
def words(text):
return ' '.join(text)
resources :links do
get :latest
resources :comments
end
require 'spec_helper'
describe AController do
describe 'GET index' do
it 'returns the full list' do
Model.should_receive(:find).with(:all)
get :index
response.code.should eq ("200")
[47, 46, 45, ...].each do |i|
validates_numericality_of :"size_#{i}_quantity"
define_method :"size_#{i}_quantity" do
if self.variants.find_by_size(i)
self.variants.count_on_hand
else
0
end
end
describe PostsController do
describe "PUT #update" do
let(:post) { Factory(:post) }
before(:each) do
sign_in user # user is defined as a memoized helper method using let { } below
put :update, :id => post.id, :body => "new content"
end
describe PostsController do
describe "GET #index" do
end
describe "GET #show" do
end
describe "POST #create" do
end
describe PostsController do
describe "PUT #update" do
it "allows an author to edit a post" do
post = Factory(:post)
sign_in post.author
put :update, :id => post.id, :body => "new content"
response.should be_successful
end
# Run with:
# rspec --color -d spec --format CustomFormatter --require ./spec/support/custom_formatter.rb
require "rspec/core/formatters/documentation_formatter"
class CustomFormatter < RSpec::Core::Formatters::DocumentationFormatter
def example_group_started(example_group)
output.puts example_group.file_path if @group_level == 0
super(example_group)
end
post = BlogPost.find("4e13cda850b86112c9000001")
# ... some operations that take some time ...
post.save