This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#RSpec Mocks... | |
it "does something with a collaborator" do | |
#Given | |
collab = mock(:collab) | |
it.collaborator = collab | |
#Then | |
collab.should_receive(:call).with(3) | |
#When |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#RSpec Mocks... | |
it "does something with a collaborator" do | |
#Given | |
collab = mock(:collab) | |
it.collaborator = collab | |
#Then | |
collab.should_receive(:call).with(3) | |
#When |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassProjectsController < ApplicationController | |
def new | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'): |