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
require 'matchers.rb'
describe CheckOut do
let(:checkout) { CheckOut.new(RULES) }
context "calculating totals" do
subject { checkout }
it { should price("").at(0) }
it { should price("A").at(50) }
@dchelimsky
dchelimsky / capybara_string_matchers.rb
Created January 10, 2011 13:14
Potential approach for rspec-2 matchers using Capybara::string
module CapybaraStringMatchers
extend RSpec::Matchers::DSL
matcher :have_selector do |selector|
match do |html|
simplified(html).has_selector?(selector)
end
failure_message_for_should do |html|
"expected to find selector #{selector.inspect} in:\n#{html.to_s}"
# if you're converting a stock rails test/unit suite to rspec-2, this little business can help
module TestToSpec
def self.included(includer)
includer.class_eval do
def test(*args, &block)
example(*args, &block)
end
end
end
$ be cucumber features/subject/attribute_of_subject.feature:104 --format pretty
Using the default profile...
Feature: attribute of subject
Use the its() method as a short-hand to generate a nested example group with
a single example that specifies the expected value of an attribute of the
subject. This can be used with an implicit or explicit subject.
its() accepts a symbol or a string, and a block representing the example.
its(:size) { should eq(1) }
diff --git a/spec/autotest/failed_results_re_spec.rb b/spec/autotest/failed_results_re_spec.rb
index ea04333..a536c9c 100644
--- a/spec/autotest/failed_results_re_spec.rb
+++ b/spec/autotest/failed_results_re_spec.rb
@@ -18,6 +18,11 @@ describe "failed_results_re for autotest" do
it "matches a failure" do
re = Autotest::Rspec2.new.failed_results_re
+ puts "*"*50
+ p re
$ rvm -v
rvm 1.2.7 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/]
$ gem -v
1.5.2
$ gem list
*** LOCAL GEMS ***
module MyModule
def some_method
super
rescue SystemStackError => e
puts "you're including MyModule more than once"
end
end
class MyBaseClass; end
shared_thingy("string"){ ... }
shared_thingy(:symbol){ ... }
shared_thingy(:key => :value){ ... }
describe "something", :key => :value do
# ^^ evals the block in the host group
describe "something", :symbol do
# ^^ evals the block in the host group if treating symbols as metadata
require 'spec_helper'
describe ArticlesController, :type => :controller do
# ^^ :type => :controller is not necessary if the file is in spec/controllers
describe "GET index" do
# ^^ The describe method creates an example group. ^^
get :index
# ^^ The get method is exposed to an example.
response.should be_successful
end
# -------------------------------------
# DECLARATION
# using strings for explicit inclusion
shared 'logged in as admin' do
before { login_as admin_user }
end
shared 'a model with a slug' do
it 'sets the slug column upon initialization' do