Skip to content

Commit

Permalink
Extracted context framework
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Dec 15, 2010
1 parent acb71a6 commit d33b7da
Show file tree
Hide file tree
Showing 280 changed files with 764 additions and 18,581 deletions.
13 changes: 0 additions & 13 deletions .autotest

This file was deleted.

2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_DISABLE_SHARED_GEMS: "1"
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
test/*/log/*.log
doc
coverage
.svn/
pkg
*.swp
*.swo
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTION_GUIDELINES.rdoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
We're using GitHub[http://github.com/thoughtbot/shoulda/tree/master], and we've been getting any combination of github pull requests, tickets, patches, emails, etc. We need to normalize this workflow to make sure we don't miss any fixes.
We're using GitHub[http://github.com/thoughtbot/shoulda-context], and we've been getting any combination of github pull requests, tickets, patches, emails, etc. We need to normalize this workflow to make sure we don't miss any fixes.

* Make sure you're accessing the source from the {official repository}[http://github.com/thoughtbot/shoulda/tree/master].
* Make sure you're accessing the source from the {official repository}[http://github.com/thoughtbot/shoulda-context].
* We prefer git branches over patches, but we can take either.
* If you're using git, please make a branch for each separate contribution. We can cherry pick your commits, but pulling from a branch is easier.
* If you're submitting patches, please cut each fix or feature into a separate patch.
* There should be an issue[http://github.com/thoughtbot/shoulda/issues] for any submission. If you've found a bug and want to fix it, open a new ticket at the same time.
* There should be an issue[http://github.com/thoughtbot/shoulda-context/issues] for any submission. If you've found a bug and want to fix it, open a new ticket at the same time.
* Please <b>don't send pull requests</b> Just update the issue with the url for your fix (or attach the patch) when it's ready. The github pull requests pretty much get dropped on the floor until someone with commit rights notices them in the mailbox.
* Contributions without tests won't be accepted. The file <tt>/test/README</tt> explains the testing system pretty thoroughly.

5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'http://rubygems.org'

gem 'mocha'
gem 'ruby-debug'

20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GEM
remote: http://rubygems.org/
specs:
columnize (0.3.2)
linecache (0.43)
mocha (0.9.10)
rake
rake (0.8.7)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)

PLATFORMS
ruby

DEPENDENCIES
mocha
ruby-debug
114 changes: 6 additions & 108 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,65 +1,10 @@
= Shoulda - Making tests easy on the fingers and eyes
= should-context - a context framework for Test::Unit

Shoulda makes it easy to write elegant, understandable, and maintainable tests. Shoulda consists of matchers, test helpers, and assertions. It's fully compatible with your existing tests in Test::Unit or RSpec, and requires no retooling to use.
Shoulda's contexts make it easy to write elegant, understandable, and maintainable tests for Test::Unit. It's fully compatible with your existing tests in Test::Unit, and requires no retooling to use.

Matchers:: Test::Unit- and RSpec-compatible one-liners that test common Rails functionality.
These tests would otherwise be much longer, more complex, and error-prone.
Helpers:: #context and #should give you RSpec like test blocks in Test::Unit.
In addition, you get nested contexts and a much more readable syntax.
Assertions:: Many common Rails testing idioms have been distilled into a set of useful assertions.
The #context and #should methods give you RSpec like test blocks in Test::Unit.

= Usage

=== ActiveRecord Tests (Shoulda::ActiveRecord::Matchers)

Test your ActiveRecord associations and validations with these powerful matchers:

class PostTest < Test::Unit::TestCase
should belong_to(:user)
should have_many(:tags).through(:taggings)

should validate_uniqueness_of(:title)
should validate_presence_of(:body).with_message(/wtf/)
should validate_presence_of(:title)
should validate_numericality_of(:user_id)
end

class UserTest < Test::Unit::TestCase
should have_many(:posts)

should_not allow_value("blah").for(:email)
should_not allow_value("b lah").for(:email)
should allow_value("[email protected]").for(:email)
should allow_value("[email protected]").for(:email)
should ensure_inclusion_of(:email).in_range(1..100)
should ensure_inclusion_of(:age).in_range(1..100)
should_not allow_mass_assignment_of(:password)
end

Makes TDD so much easier.

=== Controller Tests (Shoulda::Controller::Matchers)

Matchers to test the most common controller patterns...

class PostsControllerTest < ActionController::TestCase
context "on GET to :show for first record" do
setup do
get :show, :id => 1
end

should assign_to(:user)
should respond_with(:success)
should render_template(:show)
should_not set_the_flash

should "do something else really cool" do
assert_equal 1, assigns(:user).id
end
end
end

=== Context Helpers (Shoulda::Context)
== Contexts

Stop killing your fingers with all of those underscores... Name your tests with plain sentences!

Expand Down Expand Up @@ -92,63 +37,16 @@ Produces the following test methods:

So readable!

=== Helpful Assertions (Shoulda::Assertions)

More to come here, but have fun with what's there.
== Assertions

assert_same_elements([:a, :b, :c], [:c, :a, :b])
assert_contains(['a', '1'], /\d/)
assert_contains(['a', '1'], 'a')

= Rails Installation (Test::Unit)

Specify the gem dependency in your config/environment.rb file:

Rails::Initializer.run do |config|
config.gem "shoulda", :lib => "shoulda"
end

Then:

$ rake gems:install
$ rake gems:unpack

= Rails Installation (RSpec)

If you're using Shoulda with RSpec, we recommend that you add config.gem lines
for RSpec and Shoulda in your config/environment/test.rb file, but do not ask
Rails to load the RSpec and Shoulda libraries:

config.gem 'rspec', :lib => false
config.gem 'rspec-rails', :lib => false
config.gem 'shoulda', :lib => false

Then require shoulda from your spec/spec_helper.rb file, before Spec::Runner is
configured:

# requires for RSpec
require 'shoulda'
Spec::Runner.configure do |config|
# ...

You should not need to require anything besides the top-level shoulda library.

= Rails 3 Installation (RSpec)

With Rails 3 and Bundler, requiring Shoulda is as easy as adding it to your Gemfile:

group :test do
gem "shoulda"
gem "rspec-rails", "2.0.0.beta.12"
end

Shoulda will automatically include matchers into the appropriate example
groups.

= Credits

Shoulda is maintained and funded by {thoughtbot}[http://thoughtbot.com/community]

= License

Shoulda is Copyright © 2006-2010 Tammer Saleh, Thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
Shoulda is Copyright © 2010 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
42 changes: 6 additions & 36 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
require 'rubygems'
require 'bundler/setup'
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
begin
require 'cucumber/rake/task'
rescue LoadError
warn "couldn't load cucumber, skipping"
end

$LOAD_PATH.unshift("lib")
require 'shoulda/version'
load 'tasks/shoulda.rake'

# Test::Unit::UI::VERBOSE
test_files_pattern = 'test/{unit,functional,other,matchers}/**/*_test.rb'
test_files_pattern = 'test/**/*_test.rb'
Rake::TestTask.new do |t|
t.libs << 'lib' << 'test'
t.pattern = test_files_pattern
Expand All @@ -23,7 +17,7 @@ end

Rake::RDocTask.new { |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = "Shoulda -- Making tests easy on the fingers and eyes"
rdoc.title = "shoulda-context -- Context framework for Test::Unit"
rdoc.options << '--line-numbers'
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
rdoc.rdoc_files.include('README.rdoc', 'CONTRIBUTION_GUIDELINES.rdoc', 'lib/**/*.rb')
Expand All @@ -36,7 +30,7 @@ task :coverage do
system "rcov --rails --sort coverage -Ilib #{files.join(' ')}"
end

eval("$specification = begin; #{IO.read('shoulda.gemspec')}; end")
eval("$specification = begin; #{IO.read('shoulda-context.gemspec')}; end")
Rake::GemPackageTask.new $specification do |pkg|
pkg.need_tar = true
pkg.need_zip = true
Expand All @@ -45,30 +39,6 @@ end
desc "Clean files generated by rake tasks"
task :clobber => [:clobber_rdoc, :clobber_package]

namespace :cucumber do
Cucumber::Rake::Task.new(:rails2, "Run the cucumber features in Rails 2") do |t|
t.fork = true
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
t.profile = 'rails2'
end

Cucumber::Rake::Task.new(:rails3, "Run the cucumber features in Rails 3") do |t|
t.fork = true
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
t.profile = 'rails3'
end
end rescue nil

desc "Run the cucumber features in both Rails 2 and 3"
task :cucumber => ["cucumber:rails2", "cucumber:rails3"]

desc 'run tests for all supported versions of Rails'
task :test_all do
%w(2.3.8 3.0.0.beta4).each do |version|
system("RAILS_VERSION=#{version} rake -s test;")
end
end

desc 'Default: run test and cucumber features for support versions'
task :default => [:test_all, :cucumber]
desc 'Default: run tests'
task :default => [:test]

2 changes: 0 additions & 2 deletions cucumber.yml

This file was deleted.

115 changes: 0 additions & 115 deletions features/rails_integration.feature

This file was deleted.

Loading

0 comments on commit d33b7da

Please sign in to comment.