Permalink
Browse files

Removed all ThoughtBot (and Thoughtbot) namespaces

  • Loading branch information...
webmat committed Jan 5, 2009
1 parent 5ede009 commit 5c1329f6b9068c879d3d3182610b992c64ba2519
View
@@ -10,7 +10,7 @@ Assertions:: Many common rails testing idioms have been distilled into a set of
= Usage
-=== Context Helpers (ThoughtBot::Shoulda::Context)
+=== Context Helpers (Shoulda::Context)
Stop killing your fingers with all of those underscores... Name your tests with plain sentences!
@@ -43,7 +43,7 @@ Produces the following test methods:
So readable!
-=== ActiveRecord Tests (ThoughtBot::Shoulda::ActiveRecord::Macros)
+=== ActiveRecord Tests (Shoulda::ActiveRecord::Macros)
Quick macro tests for your ActiveRecord associations and validations:
@@ -71,7 +71,7 @@ Quick macro tests for your ActiveRecord associations and validations:
Makes TDD so much easier.
-=== Controller Tests (ThoughtBot::Shoulda::Controller::Macros)
+=== Controller Tests (Shoulda::Controller::Macros)
Macros to test the most common controller patterns...
@@ -90,7 +90,7 @@ Macros to test the most common controller patterns...
end
end
-=== Helpful Assertions (ThoughtBot::Shoulda::Assertions)
+=== Helpful Assertions (Shoulda::Assertions)
More to come here, but have fun with what's there.
View
@@ -38,7 +38,7 @@ task :default => ['test']
spec = Gem::Specification.new do |s|
s.name = "shoulda"
- s.version = Thoughtbot::Shoulda::VERSION
+ s.version = Shoulda::VERSION
s.summary = "Making tests easy on the fingers and eyes"
s.homepage = "http://thoughtbot.com/projects/shoulda"
s.rubyforge_project = "shoulda"
View
@@ -8,10 +8,10 @@
module Test # :nodoc: all
module Unit
class TestCase
- extend Thoughtbot::Shoulda
- include ThoughtBot::Shoulda::Assertions
- extend ThoughtBot::Shoulda::Macros
- include ThoughtBot::Shoulda::Helpers
+ extend Shoulda
+ include Shoulda::Assertions
+ extend Shoulda::Macros
+ include Shoulda::Helpers
end
end
end
@@ -4,7 +4,7 @@
module Test # :nodoc: all
module Unit
class TestCase
- include ThoughtBot::Shoulda::ActionMailer::Assertions
+ include Shoulda::ActionMailer::Assertions
end
end
end
@@ -1,39 +1,38 @@
-module ThoughtBot # :nodoc:
- module Shoulda # :nodoc:
- module ActionMailer # :nodoc:
- module Assertions
- # Asserts that an email was delivered. Can take a block that can further
- # narrow down the types of emails you're expecting.
- #
- # assert_sent_email
- #
- # Passes if ActionMailer::Base.deliveries has an email
- #
- # assert_sent_email do |email|
- # email.subject =~ /hi there/ && email.to.include?('none@none.com')
- # end
- #
- # Passes if there is an email with subject containing 'hi there' and
- # 'none@none.com' as one of the recipients.
- #
- def assert_sent_email
- emails = ::ActionMailer::Base.deliveries
- assert !emails.empty?, "No emails were sent"
- if block_given?
- matching_emails = emails.select {|email| yield email }
- assert !matching_emails.empty?, "None of the emails matched."
- end
+module Shoulda # :nodoc:
+ module ActionMailer # :nodoc:
+ module Assertions
+ # Asserts that an email was delivered. Can take a block that can further
+ # narrow down the types of emails you're expecting.
+ #
+ # assert_sent_email
+ #
+ # Passes if ActionMailer::Base.deliveries has an email
+ #
+ # assert_sent_email do |email|
+ # email.subject =~ /hi there/ && email.to.include?('none@none.com')
+ # end
+ #
+ # Passes if there is an email with subject containing 'hi there' and
+ # 'none@none.com' as one of the recipients.
+ #
+ def assert_sent_email
+ emails = ::ActionMailer::Base.deliveries
+ assert !emails.empty?, "No emails were sent"
+ if block_given?
+ matching_emails = emails.select {|email| yield email }
+ assert !matching_emails.empty?, "None of the emails matched."
end
+ end
- # Asserts that no ActionMailer mails were delivered
- #
- # assert_did_not_send_email
- def assert_did_not_send_email
- msg = "Sent #{::ActionMailer::Base.deliveries.size} emails.\n"
- ::ActionMailer::Base.deliveries.each { |m| msg << " '#{m.subject}' sent to #{m.to.to_sentence}\n" }
- assert ::ActionMailer::Base.deliveries.empty?, msg
- end
+ # Asserts that no ActionMailer mails were delivered
+ #
+ # assert_did_not_send_email
+ def assert_did_not_send_email
+ msg = "Sent #{::ActionMailer::Base.deliveries.size} emails.\n"
+ ::ActionMailer::Base.deliveries.each { |m| msg << " '#{m.subject}' sent to #{m.to.to_sentence}\n" }
+ assert ::ActionMailer::Base.deliveries.empty?, msg
end
end
end
end
+
@@ -5,8 +5,8 @@
module Test # :nodoc: all
module Unit
class TestCase
- include ThoughtBot::Shoulda::ActiveRecord::Assertions
- extend ThoughtBot::Shoulda::ActiveRecord::Macros
+ include Shoulda::ActiveRecord::Assertions
+ extend Shoulda::ActiveRecord::Macros
end
end
end
@@ -1,86 +1,84 @@
-module ThoughtBot # :nodoc:
- module Shoulda # :nodoc:
- module ActiveRecord # :nodoc:
- module Assertions
- # Asserts that the given object can be saved
- #
- # assert_save User.new(params)
- def assert_save(obj)
- assert obj.save, "Errors: #{pretty_error_messages obj}"
- obj.reload
- end
+module Shoulda # :nodoc:
+ module ActiveRecord # :nodoc:
+ module Assertions
+ # Asserts that the given object can be saved
+ #
+ # assert_save User.new(params)
+ def assert_save(obj)
+ assert obj.save, "Errors: #{pretty_error_messages obj}"
+ obj.reload
+ end
- # Asserts that the given object is valid
- #
- # assert_valid User.new(params)
- def assert_valid(obj)
- assert obj.valid?, "Errors: #{pretty_error_messages obj}"
- end
+ # Asserts that the given object is valid
+ #
+ # assert_valid User.new(params)
+ def assert_valid(obj)
+ assert obj.valid?, "Errors: #{pretty_error_messages obj}"
+ end
- # Asserts that an Active Record model validates with the passed
- # <tt>value</tt> by making sure the <tt>error_message_to_avoid</tt> is not
- # contained within the list of errors for that attribute.
- #
- # assert_good_value(User.new, :email, "user@example.com")
- # assert_good_value(User.new, :ssn, "123456789", /length/)
- #
- # If a class is passed as the first argument, a new object will be
- # instantiated before the assertion. If an instance variable exists with
- # the same name as the class (underscored), that object will be used
- # instead.
- #
- # assert_good_value(User, :email, "user@example.com")
- #
- # @product = Product.new(:tangible => false)
- # assert_good_value(Product, :price, "0")
- def assert_good_value(object_or_klass, attribute, value, error_message_to_avoid = //)
- object = get_instance_of(object_or_klass)
- object.send("#{attribute}=", value)
- object.valid?
- assert_does_not_contain(object.errors.on(attribute), error_message_to_avoid, "when set to #{value.inspect}")
- end
+ # Asserts that an Active Record model validates with the passed
+ # <tt>value</tt> by making sure the <tt>error_message_to_avoid</tt> is not
+ # contained within the list of errors for that attribute.
+ #
+ # assert_good_value(User.new, :email, "user@example.com")
+ # assert_good_value(User.new, :ssn, "123456789", /length/)
+ #
+ # If a class is passed as the first argument, a new object will be
+ # instantiated before the assertion. If an instance variable exists with
+ # the same name as the class (underscored), that object will be used
+ # instead.
+ #
+ # assert_good_value(User, :email, "user@example.com")
+ #
+ # @product = Product.new(:tangible => false)
+ # assert_good_value(Product, :price, "0")
+ def assert_good_value(object_or_klass, attribute, value, error_message_to_avoid = //)
+ object = get_instance_of(object_or_klass)
+ object.send("#{attribute}=", value)
+ object.valid?
+ assert_does_not_contain(object.errors.on(attribute), error_message_to_avoid, "when set to #{value.inspect}")
+ end
- # Asserts that an Active Record model invalidates the passed
- # <tt>value</tt> by making sure the <tt>error_message_to_expect</tt> is
- # contained within the list of errors for that attribute.
- #
- # assert_bad_value(User.new, :email, "invalid")
- # assert_bad_value(User.new, :ssn, "123", /length/)
- #
- # If a class is passed as the first argument, a new object will be
- # instantiated before the assertion. If an instance variable exists with
- # the same name as the class (underscored), that object will be used
- # instead.
- #
- # assert_bad_value(User, :email, "invalid")
- #
- # @product = Product.new(:tangible => true)
- # assert_bad_value(Product, :price, "0")
- def assert_bad_value(object_or_klass, attribute, value,
- error_message_to_expect = self.class.default_error_message(:invalid))
- object = get_instance_of(object_or_klass)
- object.send("#{attribute}=", value)
- assert !object.valid?, "#{object.class} allowed #{value.inspect} as a value for #{attribute}"
- assert object.errors.on(attribute), "There are no errors on #{attribute} after being set to #{value.inspect}"
- assert_contains(object.errors.on(attribute), error_message_to_expect, "when set to #{value.inspect}")
- end
+ # Asserts that an Active Record model invalidates the passed
+ # <tt>value</tt> by making sure the <tt>error_message_to_expect</tt> is
+ # contained within the list of errors for that attribute.
+ #
+ # assert_bad_value(User.new, :email, "invalid")
+ # assert_bad_value(User.new, :ssn, "123", /length/)
+ #
+ # If a class is passed as the first argument, a new object will be
+ # instantiated before the assertion. If an instance variable exists with
+ # the same name as the class (underscored), that object will be used
+ # instead.
+ #
+ # assert_bad_value(User, :email, "invalid")
+ #
+ # @product = Product.new(:tangible => true)
+ # assert_bad_value(Product, :price, "0")
+ def assert_bad_value(object_or_klass, attribute, value,
+ error_message_to_expect = self.class.default_error_message(:invalid))
+ object = get_instance_of(object_or_klass)
+ object.send("#{attribute}=", value)
+ assert !object.valid?, "#{object.class} allowed #{value.inspect} as a value for #{attribute}"
+ assert object.errors.on(attribute), "There are no errors on #{attribute} after being set to #{value.inspect}"
+ assert_contains(object.errors.on(attribute), error_message_to_expect, "when set to #{value.inspect}")
+ end
- def pretty_error_messages(obj)
- obj.errors.map do |a, m|
- msg = "#{a} #{m}"
- msg << " (#{obj.send(a).inspect})" unless a.to_sym == :base
- end
+ def pretty_error_messages(obj)
+ obj.errors.map do |a, m|
+ msg = "#{a} #{m}"
+ msg << " (#{obj.send(a).inspect})" unless a.to_sym == :base
end
+ end
- private
+ private
- def get_instance_of(object_or_klass)
- if object_or_klass.is_a?(Class)
- klass = object_or_klass
- instance_variable_get("@#{klass.to_s.underscore}") || klass.new
- else
- object_or_klass
- end
+ def get_instance_of(object_or_klass)
+ if object_or_klass.is_a?(Class)
+ klass = object_or_klass
+ instance_variable_get("@#{klass.to_s.underscore}") || klass.new
+ else
+ object_or_klass
end
end
end
Oops, something went wrong.

0 comments on commit 5c1329f

Please sign in to comment.