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
@dchelimsky
dchelimsky / subject_in_each_context_spec.rb
Created May 15, 2011 13:37 — forked from subdigital/better_card_spec.rb
Better rspec structure with subject & let blocks
describe Card do
describe "#value" do
context "Two of Hearts" do
subject { Card.new("2H") }
its(:value) { should == 2 }
end
describe "Face Cards" do
context "King of Clubs" do
$(".log a").click(function() {
$("#panel-" + $(this).data("build_id") + ":hidden").trigger('showLog');
$("#panel-" + $(this).data("build_id") + ":visible").trigger('hideLog');
return false;
});
rvm @capybara-example --create
gem install bundler
gem install rails -v 3.0.7
rails new example
cd example
echo 'gem "rspec-rails", "2.6.0.rc4", :group => [:development, :test]' >> Gemfile
echo 'gem "capybara", "1.0.0.beta1", :group => [:development, :test]' >> Gemfile
bundle install
rails g rspec:install
rails g scaffold things
@dchelimsky
dchelimsky / widgets_controller_spec.out
Created April 26, 2011 12:50
Generated controller spec in rspec-rails-2.6
WidgetsController
GET index
assigns all widgets as @widgets
GET show
assigns the requested widget as @widget
GET new
assigns a new widget as @widget
GET edit
assigns the requested widget as @widget
POST create
$ ruby -v && time bundle exec rspec spec
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.6.0]
Finished in 2.53 seconds
669 examples, 0 failures, 2 pending
real 0m3.861s
user 0m3.397s
sys 0m0.405s
$ gem install rspec-rails --pre --debug
Exception `NameError' at /Users/david/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:163 - uninitialized constant Gem::Commands::InstallCommand
Exception `LoadError' at /Users/david/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29 - no such file to load -- psych
Exception `LoadError' at /Users/david/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:35 - no such file to load -- psych
Exception `NoMethodError' at /Users/david/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/requirement.rb:134 - undefined method `call' for nil:NilClass
ERROR: While executing gem ... (NoMethodError)
undefined method `call' for nil:NilClass
/Users/david/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/requirement.rb:134:in `satisfied_by?'
/Users/david/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `all?'
/Users/david/.rvm/rubies/ruby-1
module Test
module Unit
TestCase = RSpec::Core::ExampleGroup
end
end
class Test::Unit::TestCase
def self.inherited(host)
host.set_it_up host.name.gsub(/(Spec|Test)/,'')
def host.method_added(name)
describe Subscription do
describe '#api_representation' do
let(:record) { new_valid_record }
before(:each) do
record.engine_variants.first.should respond_to(:api_representation)
record.engine_variants.first.stub(api_representation: 'ev_api_representation')
record.url_fragments.first.should respond_to(:api_representation)
record.url_fragments.first.stub(api_representation: 'uf_api_representation')
require 'active_model'
require 'active_support/core_ext'
require 'rspec/rails/mocks'
describe "Foo" do
it "is mockable" do
foo = mock_model("Foo")
foo.id.should eq(1001)
foo.to_param.should eq("1001")
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