Skip to content

Commit

Permalink
Moved shoulda/gem/* to shoulda/context.rb and shoulda/proc_extensions.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
rmm5t committed Aug 31, 2008
1 parent a40f785 commit 1a119f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
17 changes: 13 additions & 4 deletions lib/shoulda.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'shoulda/gem/shoulda'
require 'shoulda/context'
require 'shoulda/proc_extensions'
require 'shoulda/private_helpers'
require 'shoulda/general'
require 'shoulda/active_record_helpers'
Expand All @@ -11,7 +12,7 @@
possible_config_paths << File.join(ENV["HOME"], ".shoulda.conf") if ENV["HOME"]
possible_config_paths << "shoulda.conf"
possible_config_paths << File.join("test", "shoulda.conf")
possible_config_paths << File.join(RAILS_ROOT, "test", "shoulda.conf") if defined?(RAILS_ROOT)
possible_config_paths << File.join(RAILS_ROOT, "test", "shoulda.conf") if defined?(RAILS_ROOT)

possible_config_paths.each do |config_file|
if File.exists? config_file
Expand All @@ -23,7 +24,15 @@
require 'shoulda/color' if shoulda_options[:color]

module Test # :nodoc: all
module Unit
module Unit
class TestCase
extend Thoughtbot::Shoulda
end
end
end

module Test # :nodoc: all
module Unit
class TestCase

include ThoughtBot::Shoulda::General
Expand All @@ -36,7 +45,7 @@ class TestCase

module ActionController #:nodoc: all
module Integration
class Session
class Session
include ThoughtBot::Shoulda::General
end
end
Expand Down
43 changes: 16 additions & 27 deletions lib/shoulda/gem/shoulda.rb → lib/shoulda/context.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require File.join(File.dirname(__FILE__), 'proc_extensions')

module Thoughtbot
module Shoulda
VERSION = '1.1.1'
Expand All @@ -25,24 +23,24 @@ def remove_context

# == Should statements
#
# Should statements are just syntactic sugar over normal Test::Unit test methods. A should block
# contains all the normal code and assertions you're used to seeing, with the added benefit that
# Should statements are just syntactic sugar over normal Test::Unit test methods. A should block
# contains all the normal code and assertions you're used to seeing, with the added benefit that
# they can be wrapped inside context blocks (see below).
#
# === Example:
#
# class UserTest << Test::Unit::TestCase
#
#
# def setup
# @user = User.new("John", "Doe")
# end
#
# should "return its full name"
# assert_equal 'John Doe', @user.full_name
# end
#
#
# end
#
#
# ...will produce the following test:
# * <tt>"test: User should return its full name. "</tt>
#
Expand Down Expand Up @@ -83,8 +81,8 @@ def should_eventually(name, options = {}, &blk)
end

# == Contexts
#
# A context block groups should statements under a common set of setup/teardown methods.
#
# A context block groups should statements under a common set of setup/teardown methods.
# Context blocks can be arbitrarily nested, and can do wonders for improving the maintainability
# and readability of your test code.
#
Expand All @@ -95,7 +93,7 @@ def should_eventually(name, options = {}, &blk)
# setup do
# @user = User.find(:first)
# end
#
#
# should "return its full name"
# assert_equal 'John Doe', @user.full_name
# end
Expand All @@ -104,36 +102,36 @@ def should_eventually(name, options = {}, &blk)
#
# This code will produce the method <tt>"test: A User instance should return its full name. "</tt>.
#
# Contexts may be nested. Nested contexts run their setup blocks from out to in before each
# Contexts may be nested. Nested contexts run their setup blocks from out to in before each
# should statement. They then run their teardown blocks from in to out after each should statement.
#
# class UserTest << Test::Unit::TestCase
# context "A User instance" do
# setup do
# @user = User.find(:first)
# end
#
#
# should "return its full name"
# assert_equal 'John Doe', @user.full_name
# end
#
#
# context "with a profile" do
# setup do
# @user.profile = Profile.find(:first)
# end
#
#
# should "return true when sent :has_profile?"
# assert @user.has_profile?
# end
# end
# end
# end
#
# This code will produce the following methods
# This code will produce the following methods
# * <tt>"test: A User instance should return its full name. "</tt>
# * <tt>"test: A User instance with a profile should return true when sent :has_profile?. "</tt>
#
# <b>Just like should statements, a context block can exist next to normal <tt>def test_the_old_way; end</tt>
# <b>Just like should statements, a context block can exist next to normal <tt>def test_the_old_way; end</tt>
# tests</b>. This means you do not have to fully commit to the context/should syntax in a test file.

def context(name, &blk)
Expand Down Expand Up @@ -214,9 +212,9 @@ def create_test_from_should_hash(should)
test_name = ["test:", full_name, "should", "#{should[:name]}. "].flatten.join(' ').to_sym

if test_unit_class.instance_methods.include?(test_name.to_s)
warn " * WARNING: '#{test_name}' is already defined"
warn " * WARNING: '#{test_name}' is already defined"
end

context = self
test_unit_class.send(:define_method, test_name) do
begin
Expand Down Expand Up @@ -276,12 +274,3 @@ def method_missing(method, *args, &blk)
end
end
end

module Test # :nodoc: all
module Unit
class TestCase
extend Thoughtbot::Shoulda
end
end
end

File renamed without changes.

0 comments on commit 1a119f0

Please sign in to comment.