Skip to content

Instantly share code, notes, and snippets.

View dchelimsky's full-sized avatar

David Chelimsky dchelimsky

  • Retired
  • Chicago, IL, USA
View GitHub Profile
#RSpec Mocks...
it "does something with a collaborator" do
#Given
collab = mock(:collab)
it.collaborator = collab
#Then
collab.should_receive(:call).with(3)
#When
#RSpec Mocks...
it "does something with a collaborator" do
#Given
collab = mock(:collab)
it.collaborator = collab
#Then
collab.should_receive(:call).with(3)
#When
@dchelimsky
dchelimsky / gist:590557
Created September 21, 2010 21:10 — forked from qrush/gist:590466
describe SomeClass do
freeze { 1.day.from_now }
it "does some stuff with time" do
end
end
# this actually does...
describe SomeClass do
around { |example| Timecop.freeze(1.day.from_now, &example) }
class ClassProjectsController < ApplicationController
def new
end
end
shared_examples_for "a measurable object" do |measurement_method, measurement|
it "should return #{measurement} from ##{measurement_method}" do
subject.send(measurement_method).should == measurement
end
end
describe Array do
it_should_behave_like "a measurable object", :size, 2 do
subject { [2, 13] }
end
diff --git a/features/view_specs/view_spec.feature b/features/view_specs/view_spec.feature
index e85c306..6534c30 100644
--- a/features/view_specs/view_spec.feature
+++ b/features/view_specs/view_spec.feature
@@ -152,3 +152,34 @@ Feature: view spec
"""
When I run "rspec spec/views"
Then the output should contain "1 example, 0 failures"
+
+ Scenario: spec with view that accesses helper_method helpers
# Gemfile
source 'http://rubygems.org'
gem 'acts_as_list', '0.1.2'
gem 'acts_as_singleton', :git => 'git://github.com/stephencelis/acts_as_singleton.git'
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
gem 'aws-s3', '0.6.2'
gem 'cancan', '1.1.1'
gem 'delayed_job', '2.0.3'
class Photo
belongs_to :photo_album
def set_cover(cover)
if cover
photo_album.cover = self
elsif photo_album.cover.nil?
# set album cover to first photo album if no cover has been set.
photo_album.cover = photo_album.photos.first
Spec::Matchers.define :have_a_machinist_blueprint do
match do |model|
model.class.respond_to?(:make)
end
description do
"works if there's a valid blueprint"
end
failure_message_for_should do |model|
# Here are a couple of alternative suggestions for PSpec (see http://gist.github.com/305174).
# I'm not in love with any of these ideas, but hopefully they'll provide some food for thought.
#
# I like using strings for test names, so I like the 'with xxx' syntax, but I think that
# the 'with describe' doesn't makke sense - how about 'with subject':
with subject('calculator'):
with expectation('adds positive integers'):
expect(Calculator.add(1, 1)) == 2
with expectation('adds negative integers'):