Skip to content

Commit

Permalink
Extracted the context framework, switched to rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jan 19, 2011
1 parent a01e60a commit ada334c
Show file tree
Hide file tree
Showing 200 changed files with 1,733 additions and 3,529 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
@@ -0,0 +1,2 @@
---
BUNDLE_DISABLE_SHARED_GEMS: "1"
9 changes: 9 additions & 0 deletions Gemfile
@@ -0,0 +1,9 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0.beta4'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'mocha'
gem 'rspec-rails', '2.0.0.beta.12'
gem 'ruby-debug'
gem 'cucumber'

115 changes: 115 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,115 @@
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.0.beta4)
actionpack (= 3.0.0.beta4)
mail (~> 2.2.3)
actionpack (3.0.0.beta4)
activemodel (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
builder (~> 2.1.2)
erubis (~> 2.6.5)
i18n (~> 0.4.1)
rack (~> 1.1.0)
rack-mount (~> 0.6.3)
rack-test (~> 0.5.4)
tzinfo (~> 0.3.16)
activemodel (3.0.0.beta4)
activesupport (= 3.0.0.beta4)
builder (~> 2.1.2)
i18n (~> 0.4.1)
activerecord (3.0.0.beta4)
activemodel (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
arel (~> 0.4.0)
tzinfo (~> 0.3.16)
activeresource (3.0.0.beta4)
activemodel (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
activesupport (3.0.0.beta4)
arel (0.4.0)
activesupport (>= 3.0.0.beta)
builder (2.1.2)
columnize (0.3.1)
cucumber (0.9.4)
builder (~> 2.1.2)
diff-lcs (~> 1.1.2)
gherkin (~> 2.2.9)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
gherkin (2.2.9)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
i18n (0.4.1)
json (1.4.6)
linecache (0.43)
mail (2.2.12)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
mocha (0.9.10)
rake
nokogiri (1.4.4)
polyglot (0.3.1)
rack (1.1.0)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-test (0.5.6)
rack (>= 1.0)
rails (3.0.0.beta4)
actionmailer (= 3.0.0.beta4)
actionpack (= 3.0.0.beta4)
activerecord (= 3.0.0.beta4)
activeresource (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
bundler (>= 0.9.26)
railties (= 3.0.0.beta4)
railties (3.0.0.beta4)
actionpack (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
rake (>= 0.8.3)
thor (~> 0.13.6)
rake (0.8.7)
rspec (2.0.0.beta.12)
rspec-core (= 2.0.0.beta.12)
rspec-expectations (= 2.0.0.beta.12)
rspec-mocks (= 2.0.0.beta.12)
rspec-core (2.0.0.beta.12)
rspec-expectations (2.0.0.beta.12)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.0.beta.12)
rspec-rails (2.0.0.beta.12)
rspec (= 2.0.0.beta.12)
webrat (>= 0.7.0)
ruby-debug (0.10.3)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.3.0)
ruby-debug-base (0.10.3)
linecache (>= 0.3)
sqlite3-ruby (1.3.2)
term-ansicolor (1.0.5)
thor (0.13.8)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
webrat (0.7.2)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)

PLATFORMS
ruby

DEPENDENCIES
cucumber
mocha
rails (= 3.0.0.beta4)
rspec-rails (= 2.0.0.beta.12)
ruby-debug
sqlite3-ruby
34 changes: 13 additions & 21 deletions Rakefile
@@ -1,25 +1,13 @@
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
require 'rspec/core/rake_task'
require 'cucumber/rake/task'

$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'
Rake::TestTask.new do |t|
t.libs << 'lib' << 'test'
t.pattern = test_files_pattern
t.verbose = false
end

Rake::RDocTask.new { |rdoc|
rdoc.rdoc_dir = 'doc'
Expand All @@ -29,11 +17,15 @@ Rake::RDocTask.new { |rdoc|
rdoc.rdoc_files.include('README.rdoc', 'CONTRIBUTION_GUIDELINES.rdoc', 'lib/**/*.rb')
}

RSpec::Core::RakeTask.new do |t|
t.pattern = "spec/**/*_spec.rb"
end

desc "Run code-coverage analysis using rcov"
task :coverage do
rm_rf "coverage"
files = Dir[test_files_pattern]
system "rcov --rails --sort coverage -Ilib #{files.join(' ')}"
RSpec::Core::RakeTask.new(:coverage) do |t|
t.rcov = true
t.rcov_opts = %{--exclude osx\/objc,spec,gems\/ --failure-threshold 100}
t.pattern = "spec/**/*_spec.rb"
end

eval("$specification = begin; #{IO.read('shoulda.gemspec')}; end")
Expand All @@ -51,6 +43,6 @@ Cucumber::Rake::Task.new do |t|
t.profile = 'default'
end

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

42 changes: 0 additions & 42 deletions bin/convert_to_should_syntax

This file was deleted.

2 changes: 1 addition & 1 deletion features/step_definitions/rails3_steps.rb
Expand Up @@ -29,7 +29,7 @@
end

When /^I configure the application to use rspec\-rails$/ do
append_to_gemfile "gem 'rspec-rails', '>= 2.0.0.beta.12'"
append_to_gemfile "gem 'rspec-rails', '= 2.0.0.beta.12'"
steps %{And I run "bundle install"}
end

Expand Down
1 change: 0 additions & 1 deletion init.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/shoulda.rb
Expand Up @@ -5,3 +5,4 @@
else
require 'shoulda/integrations/test_unit'
end

48 changes: 34 additions & 14 deletions lib/shoulda/action_controller.rb
@@ -1,19 +1,39 @@
require 'shoulda'
require 'shoulda/action_controller/matchers'
require 'shoulda/action_controller/assign_to_matcher'
require 'shoulda/action_controller/filter_param_matcher'
require 'shoulda/action_controller/set_the_flash_matcher'
require 'shoulda/action_controller/render_with_layout_matcher'
require 'shoulda/action_controller/respond_with_matcher'
require 'shoulda/action_controller/respond_with_content_type_matcher'
require 'shoulda/action_controller/set_session_matcher'
require 'shoulda/action_controller/route_matcher'
require 'shoulda/action_controller/redirect_to_matcher'
require 'shoulda/action_controller/render_template_matcher'

module Test # :nodoc: all
module Unit
class TestCase
include Shoulda::ActionController::Matchers
extend Shoulda::ActionController::Matchers
end
end
end
module Shoulda # :nodoc:
module ActionController # :nodoc:

if defined?(ActionController::TestCase)
class ActionController::TestCase
def subject
@controller
# By using the matchers you can quickly and easily create concise and
# easy to read test suites.
#
# This code segment:
#
# describe UsersController, "on GET to show with a valid id" do
# before(:each) do
# get :show, :id => User.first.to_param
# end
#
# it { should assign_to(:user) }
# it { should respond_with(:success) }
# it { should render_template(:show) }
# it { should not_set_the_flash) }
#
# it "should do something else really cool" do
# assigns[:user].id.should == 1
# end
# end
#
# Would produce 5 tests for the show action
module Matchers
end
end
end
50 changes: 50 additions & 0 deletions lib/shoulda/action_controller/filter_param_matcher.rb
@@ -0,0 +1,50 @@
module Shoulda # :nodoc:
module ActionController # :nodoc:
module Matchers

# Ensures that filter_parameter_logging is set for the specified key.
#
# Example:
#
# it { should filter_param(:password) }
def filter_param(key)
FilterParamMatcher.new(key)
end

class FilterParamMatcher # :nodoc:

def initialize(key)
@key = key.to_s
end

def matches?(controller)
@controller = controller
filters_key?
end

def failure_message
"Expected #{@key} to be filtered; filtered keys: #{filtered_keys.join(', ')}"
end

def negative_failure_message
"Did not expect #{@key} to be filtered"
end

def description
"filter #{@key}"
end

private

def filters_key?
filtered_keys.include?(@key)
end

def filtered_keys
Rails.application.config.filter_parameters.map { |filter| filter.to_s }
end
end

end
end
end
39 changes: 0 additions & 39 deletions lib/shoulda/action_controller/matchers.rb

This file was deleted.

0 comments on commit ada334c

Please sign in to comment.