mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Cosmetic: Whitespace
This commit is contained in:
parent
226f5b8f63
commit
e2ae4a2596
27 changed files with 148 additions and 151 deletions
|
@ -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/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.
|
||||
|
||||
* Make sure you're accessing the source from the {official repository}[http://github.com/thoughtbot/shoulda/tree/master].
|
||||
* 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 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
|
||||
|
|
|
@ -14,24 +14,24 @@ module Shoulda # :nodoc:
|
|||
|
||||
# By using the macro helpers 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
|
||||
|
|
|
@ -63,7 +63,7 @@ module Shoulda # :nodoc:
|
|||
"Expected action to assign a value for @#{@variable}"
|
||||
false
|
||||
else
|
||||
@negative_failure_message =
|
||||
@negative_failure_message =
|
||||
"Didn't expect action to assign a value for @#{@variable}, " <<
|
||||
"but it was assigned to #{assigned_value.inspect}"
|
||||
true
|
||||
|
|
|
@ -34,7 +34,7 @@ module Shoulda # :nodoc:
|
|||
def description
|
||||
"respond with content type of #{@content_type}"
|
||||
end
|
||||
|
||||
|
||||
def matches?(controller)
|
||||
@controller = controller
|
||||
if @content_type.is_a?(Regexp)
|
||||
|
@ -43,32 +43,32 @@ module Shoulda # :nodoc:
|
|||
response_content_type == @content_type
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def failure_message
|
||||
"Expected #{expectation}"
|
||||
end
|
||||
|
||||
|
||||
def negative_failure_message
|
||||
"Did not expect #{expectation}"
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def response_content_type
|
||||
@controller.response.content_type.to_s
|
||||
end
|
||||
|
||||
|
||||
def lookup_by_extension(extension)
|
||||
Mime::Type.lookup_by_extension(extension.to_s).to_s
|
||||
end
|
||||
|
||||
|
||||
def expectation
|
||||
"content type to be #{@content_type}, " <<
|
||||
"but was #{response_content_type}"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,16 +24,16 @@ module Shoulda # :nodoc:
|
|||
def initialize(status)
|
||||
@status = symbol_to_status_code(status)
|
||||
end
|
||||
|
||||
|
||||
def matches?(controller)
|
||||
@controller = controller
|
||||
correct_status_code? || correct_status_code_range?
|
||||
end
|
||||
|
||||
|
||||
def failure_message
|
||||
"Expected #{expectation}"
|
||||
end
|
||||
|
||||
|
||||
def negative_failure_message
|
||||
"Did not expect #{expectation}"
|
||||
end
|
||||
|
@ -41,29 +41,29 @@ module Shoulda # :nodoc:
|
|||
def description
|
||||
"respond with #{@status}"
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def correct_status_code?
|
||||
response_code == @status
|
||||
end
|
||||
|
||||
|
||||
def correct_status_code_range?
|
||||
@status.is_a?(Range) &&
|
||||
@status.include?(response_code)
|
||||
end
|
||||
|
||||
|
||||
def response_code
|
||||
@controller.response.response_code
|
||||
end
|
||||
|
||||
|
||||
def symbol_to_status_code(potential_symbol)
|
||||
case potential_symbol
|
||||
when :success then 200
|
||||
when :redirect then 300..399
|
||||
when :missing then 404
|
||||
when :error then 500..599
|
||||
when Symbol
|
||||
when Symbol
|
||||
if defined?(::Rack::Utils::SYMBOL_TO_STATUS_CODE)
|
||||
::Rack::Utils::SYMBOL_TO_STATUS_CODE[potential_symbol]
|
||||
else
|
||||
|
@ -73,13 +73,13 @@ module Shoulda # :nodoc:
|
|||
potential_symbol
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def expectation
|
||||
"response to be a #{@status}, but was #{response_code}"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -71,7 +71,7 @@ module Shoulda # :nodoc:
|
|||
|
||||
def route_recognized?
|
||||
begin
|
||||
@context.send(:assert_routing,
|
||||
@context.send(:assert_routing,
|
||||
{ :method => @method, :path => @path },
|
||||
@params)
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ module Shoulda # :nodoc:
|
|||
module ActiveRecord # :nodoc:
|
||||
module Helpers
|
||||
def pretty_error_messages(obj) # :nodoc:
|
||||
obj.errors.map do |a, m|
|
||||
msg = "#{a} #{m}"
|
||||
obj.errors.map do |a, m|
|
||||
msg = "#{a} #{m}"
|
||||
msg << " (#{obj.send(a).inspect})" unless a.to_sym == :base
|
||||
end
|
||||
end
|
||||
|
|
|
@ -377,7 +377,7 @@ module Shoulda # :nodoc:
|
|||
#
|
||||
# Ensure that the given columns are defined on the models backing SQL table.
|
||||
# Also aliased to should_have_db_column for readability.
|
||||
# Takes the same options available in migrations:
|
||||
# Takes the same options available in migrations:
|
||||
# :type, :precision, :limit, :default, :null, and :scale
|
||||
#
|
||||
# Examples:
|
||||
|
@ -390,7 +390,7 @@ module Shoulda # :nodoc:
|
|||
#
|
||||
def should_have_db_columns(*columns)
|
||||
::ActiveSupport::Deprecation.warn("use: should have_db_column")
|
||||
column_type, precision, limit, default, null, scale, sql_type =
|
||||
column_type, precision, limit, default, null, scale, sql_type =
|
||||
get_options!(columns, :type, :precision, :limit,
|
||||
:default, :null, :scale, :sql_type)
|
||||
columns.each do |name|
|
||||
|
|
|
@ -70,10 +70,10 @@ module Shoulda # :nodoc:
|
|||
|
||||
def matches?(subject)
|
||||
@subject = subject
|
||||
association_exists? &&
|
||||
macro_correct? &&
|
||||
foreign_key_exists? &&
|
||||
through_association_valid? &&
|
||||
association_exists? &&
|
||||
macro_correct? &&
|
||||
foreign_key_exists? &&
|
||||
through_association_valid? &&
|
||||
dependent_correct? &&
|
||||
join_table_exists?
|
||||
end
|
||||
|
@ -160,7 +160,7 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
|
||||
def join_table_exists?
|
||||
if @macro != :has_and_belongs_to_many ||
|
||||
if @macro != :has_and_belongs_to_many ||
|
||||
::ActiveRecord::Base.connection.tables.include?(join_table.to_s)
|
||||
true
|
||||
else
|
||||
|
|
|
@ -57,7 +57,7 @@ module Shoulda # :nodoc:
|
|||
@low_message ||= :inclusion
|
||||
@high_message ||= :inclusion
|
||||
|
||||
disallows_lower_value &&
|
||||
disallows_lower_value &&
|
||||
allows_minimum_value &&
|
||||
disallows_higher_value &&
|
||||
allows_maximum_value
|
||||
|
|
|
@ -84,7 +84,7 @@ module Shoulda # :nodoc:
|
|||
def matches?(subject)
|
||||
super(subject)
|
||||
translate_messages!
|
||||
disallows_lower_length &&
|
||||
disallows_lower_length &&
|
||||
allows_minimum_length &&
|
||||
((@minimum == @maximum) ||
|
||||
(disallows_higher_length &&
|
||||
|
@ -106,7 +106,7 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
|
||||
def disallows_lower_length
|
||||
@minimum == 0 ||
|
||||
@minimum == 0 ||
|
||||
@minimum.nil? ||
|
||||
disallows_length_of(@minimum - 1, @short_message)
|
||||
end
|
||||
|
|
|
@ -24,12 +24,12 @@ module Shoulda # :nodoc:
|
|||
@macro = macro
|
||||
@column = column
|
||||
end
|
||||
|
||||
|
||||
def of_type(column_type)
|
||||
@column_type = column_type
|
||||
self
|
||||
end
|
||||
|
||||
|
||||
def with_options(opts = {})
|
||||
@precision = opts[:precision]
|
||||
@limit = opts[:limit]
|
||||
|
@ -41,8 +41,8 @@ module Shoulda # :nodoc:
|
|||
|
||||
def matches?(subject)
|
||||
@subject = subject
|
||||
column_exists? &&
|
||||
correct_column_type? &&
|
||||
column_exists? &&
|
||||
correct_column_type? &&
|
||||
correct_precision? &&
|
||||
correct_limit? &&
|
||||
correct_default? &&
|
||||
|
@ -80,7 +80,7 @@ module Shoulda # :nodoc:
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def correct_column_type?
|
||||
return true if @column_type.nil?
|
||||
if matched_column.type.to_s == @column_type.to_s
|
||||
|
@ -91,7 +91,7 @@ module Shoulda # :nodoc:
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def correct_precision?
|
||||
return true if @precision.nil?
|
||||
if matched_column.precision.to_s == @precision.to_s
|
||||
|
@ -103,7 +103,7 @@ module Shoulda # :nodoc:
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def correct_limit?
|
||||
return true if @limit.nil?
|
||||
if matched_column.limit.to_s == @limit.to_s
|
||||
|
@ -115,7 +115,7 @@ module Shoulda # :nodoc:
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def correct_default?
|
||||
return true if @default.nil?
|
||||
if matched_column.default.to_s == @default.to_s
|
||||
|
@ -127,7 +127,7 @@ module Shoulda # :nodoc:
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def correct_null?
|
||||
return true if @null.nil?
|
||||
if matched_column.null.to_s == @null.to_s
|
||||
|
@ -139,7 +139,7 @@ module Shoulda # :nodoc:
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def correct_scale?
|
||||
return true if @scale.nil?
|
||||
if matched_column.scale.to_s == @scale.to_s
|
||||
|
@ -150,7 +150,7 @@ module Shoulda # :nodoc:
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def matched_column
|
||||
model_class.columns.detect { |each| each.name == @column.to_s }
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ module Shoulda # :nodoc:
|
|||
@macro = macro
|
||||
@columns = normalize_columns_to_array(columns)
|
||||
end
|
||||
|
||||
|
||||
def unique(unique)
|
||||
@unique = unique
|
||||
self
|
||||
|
@ -51,11 +51,11 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def index_exists?
|
||||
! matched_index.nil?
|
||||
end
|
||||
|
||||
|
||||
def correct_unique?
|
||||
return true if @unique.nil?
|
||||
if matched_index.unique == @unique
|
||||
|
@ -66,7 +66,7 @@ module Shoulda # :nodoc:
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def matched_index
|
||||
indexes.detect { |each| each.columns == @columns }
|
||||
end
|
||||
|
@ -74,11 +74,11 @@ module Shoulda # :nodoc:
|
|||
def model_class
|
||||
@subject.class
|
||||
end
|
||||
|
||||
|
||||
def table_name
|
||||
model_class.table_name
|
||||
end
|
||||
|
||||
|
||||
def indexes
|
||||
::ActiveRecord::Base.connection.indexes(table_name)
|
||||
end
|
||||
|
@ -86,7 +86,7 @@ module Shoulda # :nodoc:
|
|||
def expectation
|
||||
expected = "#{model_class.name} to #{description}"
|
||||
end
|
||||
|
||||
|
||||
def index_type
|
||||
case @unique
|
||||
when nil
|
||||
|
@ -97,7 +97,7 @@ module Shoulda # :nodoc:
|
|||
'unique'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def normalize_columns_to_array(columns)
|
||||
if columns.class == Array
|
||||
columns.collect { |each| each.to_s }
|
||||
|
|
|
@ -25,7 +25,7 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
|
||||
class ValidateFormatOfMatcher < ValidationMatcher # :nodoc:
|
||||
|
||||
|
||||
def initialize(attribute)
|
||||
super
|
||||
end
|
||||
|
@ -34,13 +34,12 @@ module Shoulda # :nodoc:
|
|||
@expected_message = message if message
|
||||
self
|
||||
end
|
||||
|
||||
|
||||
def with(value)
|
||||
raise "You may not call both with and not_with" if @value_to_fail
|
||||
@value_to_pass = value
|
||||
self
|
||||
end
|
||||
|
||||
|
||||
def not_with(value)
|
||||
raise "You may not call both with and not_with" if @value_to_pass
|
||||
|
@ -48,7 +47,6 @@ module Shoulda # :nodoc:
|
|||
self
|
||||
end
|
||||
|
||||
|
||||
def matches?(subject)
|
||||
super(subject)
|
||||
@expected_message ||= :blank
|
||||
|
|
|
@ -67,8 +67,8 @@ module Shoulda # :nodoc:
|
|||
def matches?(subject)
|
||||
@subject = subject.class.new
|
||||
@expected_message ||= :taken
|
||||
find_existing &&
|
||||
set_scoped_attributes &&
|
||||
find_existing &&
|
||||
set_scoped_attributes &&
|
||||
validate_attribute &&
|
||||
validate_after_scope_change
|
||||
end
|
||||
|
@ -121,7 +121,7 @@ module Shoulda # :nodoc:
|
|||
@subject.send("#{scope}=", next_value)
|
||||
|
||||
if allows_value_of(existing_value, @expected_message)
|
||||
@negative_failure_message <<
|
||||
@negative_failure_message <<
|
||||
" (with different value of #{scope})"
|
||||
true
|
||||
else
|
||||
|
|
|
@ -18,7 +18,6 @@ module Shoulda # :nodoc:
|
|||
@subject = subject
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ module Shoulda # :nodoc:
|
|||
case x
|
||||
when Regexp
|
||||
assert(collection.detect { |e| e =~ x }, msg)
|
||||
else
|
||||
else
|
||||
assert(collection.include?(x), msg)
|
||||
end
|
||||
end
|
||||
|
@ -39,7 +39,7 @@ module Shoulda # :nodoc:
|
|||
case x
|
||||
when Regexp
|
||||
assert(!collection.detect { |e| e =~ x }, msg)
|
||||
else
|
||||
else
|
||||
assert(!collection.include?(x), msg)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
module Shoulda # :nodoc:
|
||||
# Call autoload_macros when you want to load test macros automatically in a non-Rails
|
||||
# Call autoload_macros when you want to load test macros automatically in a non-Rails
|
||||
# project (it's done automatically for Rails projects).
|
||||
# You don't need to specify ROOT/test/shoulda_macros explicitly. Your custom macros
|
||||
# are loaded automatically when you call autoload_macros.
|
||||
#
|
||||
# The first argument is the path to you application's root directory.
|
||||
# All following arguments are directories relative to your root, which contain
|
||||
# shoulda_macros subdirectories. These directories support the same kinds of globs as the
|
||||
# All following arguments are directories relative to your root, which contain
|
||||
# shoulda_macros subdirectories. These directories support the same kinds of globs as the
|
||||
# Dir class.
|
||||
#
|
||||
#
|
||||
# Basic usage (from a test_helper):
|
||||
# Shoulda.autoload_macros(File.dirname(__FILE__) + '/..')
|
||||
# will load everything in
|
||||
# - your_app/test/shoulda_macros
|
||||
# will load everything in
|
||||
# - your_app/test/shoulda_macros
|
||||
#
|
||||
# To load vendored macros as well:
|
||||
# To load vendored macros as well:
|
||||
# Shoulda.autoload_macros(APP_ROOT, 'vendor/*')
|
||||
# will load everything in
|
||||
# - APP_ROOT/vendor/*/shoulda_macros
|
||||
# - APP_ROOT/test/shoulda_macros
|
||||
# will load everything in
|
||||
# - APP_ROOT/vendor/*/shoulda_macros
|
||||
# - APP_ROOT/test/shoulda_macros
|
||||
#
|
||||
# To load macros in an app with a vendor directory laid out like Rails':
|
||||
# To load macros in an app with a vendor directory laid out like Rails':
|
||||
# Shoulda.autoload_macros(APP_ROOT, 'vendor/{plugins,gems}/*')
|
||||
# or
|
||||
# Shoulda.autoload_macros(APP_ROOT, 'vendor/plugins/*', 'vendor/gems/*')
|
||||
# will load everything in
|
||||
# - APP_ROOT/vendor/plugins/*/shoulda_macros
|
||||
# - APP_ROOT/vendor/gems/*/shoulda_macros
|
||||
# - APP_ROOT/test/shoulda_macros
|
||||
# will load everything in
|
||||
# - APP_ROOT/vendor/plugins/*/shoulda_macros
|
||||
# - APP_ROOT/vendor/gems/*/shoulda_macros
|
||||
# - APP_ROOT/test/shoulda_macros
|
||||
#
|
||||
# If you prefer to stick testing dependencies away from your production dependencies:
|
||||
# If you prefer to stick testing dependencies away from your production dependencies:
|
||||
# Shoulda.autoload_macros(APP_ROOT, 'vendor/*', 'test/vendor/*')
|
||||
# will load everything in
|
||||
# - APP_ROOT/vendor/*/shoulda_macros
|
||||
# - APP_ROOT/test/vendor/*/shoulda_macros
|
||||
# - APP_ROOT/test/shoulda_macros
|
||||
# will load everything in
|
||||
# - APP_ROOT/vendor/*/shoulda_macros
|
||||
# - APP_ROOT/test/vendor/*/shoulda_macros
|
||||
# - APP_ROOT/test/shoulda_macros
|
||||
def self.autoload_macros(root, *dirs)
|
||||
dirs << File.join('test')
|
||||
complete_dirs = dirs.map{|d| File.join(root, d, 'shoulda_macros')}
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
namespace :shoulda do
|
||||
# From http://blog.internautdesign.com/2007/11/2/a-yaml_to_shoulda-rake-task
|
||||
# David.Lowenfels@gmail.com
|
||||
desc "Converts a YAML file (FILE=./path/to/yaml) into a Shoulda skeleton"
|
||||
desc "Converts a YAML file (FILE=./path/to/yaml) into a Shoulda skeleton"
|
||||
task :from_yaml do
|
||||
require 'yaml'
|
||||
|
||||
|
||||
def yaml_to_context(hash, indent = 0)
|
||||
indent1 = ' ' * indent
|
||||
indent2 = ' ' * (indent + 1)
|
||||
hash.each_pair do |context, shoulds|
|
||||
puts indent1 + "context \"#{context}\" do"
|
||||
puts
|
||||
puts indent1 + "context \"#{context}\" do"
|
||||
puts
|
||||
shoulds.each do |should|
|
||||
yaml_to_context( should, indent + 1 ) and next if should.is_a?( Hash )
|
||||
puts indent2 + "should_eventually \"" + should.gsub(/^should +/,'') + "\" do"
|
||||
puts indent2 + "end"
|
||||
puts indent2 + "should_eventually \"" + should.gsub(/^should +/,'') + "\" do"
|
||||
puts indent2 + "end"
|
||||
puts
|
||||
end
|
||||
puts indent1 + "end"
|
||||
puts indent1 + "end"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
puts("Please pass in a FILE argument.") and exit unless ENV['FILE']
|
||||
|
||||
|
||||
yaml_to_context( YAML.load_file( ENV['FILE'] ) )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ if RAILS_ENV == 'test'
|
|||
if defined? Spec
|
||||
require 'shoulda/rspec'
|
||||
else
|
||||
require 'shoulda/rails'
|
||||
require 'shoulda/rails'
|
||||
Shoulda.autoload_macros RAILS_ROOT, File.join("vendor", "{plugins,gems}", "*")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ContextTest < ActiveSupport::TestCase # :nodoc:
|
||||
|
||||
|
||||
def self.context_macro(&blk)
|
||||
context "with a subcontext made by a macro" do
|
||||
setup { @context_macro = :foo }
|
||||
|
||||
merge_block &blk
|
||||
merge_block &blk
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,11 +21,11 @@ class ContextTest < ActiveSupport::TestCase # :nodoc:
|
|||
setup do
|
||||
@blah = "blah"
|
||||
end
|
||||
|
||||
|
||||
should "run the setup block" do
|
||||
assert_equal "blah", @blah
|
||||
end
|
||||
|
||||
|
||||
should "have name set right" do
|
||||
assert_match(/^test: context with setup block/, self.to_s)
|
||||
end
|
||||
|
@ -34,11 +34,11 @@ class ContextTest < ActiveSupport::TestCase # :nodoc:
|
|||
setup do
|
||||
@blah = "#{@blah} twice"
|
||||
end
|
||||
|
||||
|
||||
should "be named correctly" do
|
||||
assert_match(/^test: context with setup block and a subcontext should be named correctly/, self.to_s)
|
||||
end
|
||||
|
||||
|
||||
should "run the setup blocks in order" do
|
||||
assert_equal @blah, "blah twice"
|
||||
end
|
||||
|
@ -64,7 +64,7 @@ class ContextTest < ActiveSupport::TestCase # :nodoc:
|
|||
setup do
|
||||
@blah = "foo"
|
||||
end
|
||||
|
||||
|
||||
should "have @blah == 'foo'" do
|
||||
assert_equal "foo", @blah
|
||||
end
|
||||
|
@ -73,12 +73,12 @@ class ContextTest < ActiveSupport::TestCase # :nodoc:
|
|||
assert_match(/^test: another context with setup block/, self.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "context with method definition" do
|
||||
setup do
|
||||
def hello; "hi"; end
|
||||
end
|
||||
|
||||
|
||||
should "be able to read that method" do
|
||||
assert_equal "hi", hello
|
||||
end
|
||||
|
@ -87,52 +87,52 @@ class ContextTest < ActiveSupport::TestCase # :nodoc:
|
|||
assert_match(/^test: context with method definition/, self.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "another context" do
|
||||
should "not define @blah" do
|
||||
assert_nil @blah
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "context with multiple setups and/or teardowns" do
|
||||
|
||||
|
||||
cleanup_count = 0
|
||||
|
||||
|
||||
2.times do |i|
|
||||
setup { cleanup_count += 1 }
|
||||
teardown { cleanup_count -= 1 }
|
||||
end
|
||||
|
||||
|
||||
2.times do |i|
|
||||
should "call all setups and all teardowns (check ##{i + 1})" do
|
||||
assert_equal 2, cleanup_count
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "subcontexts" do
|
||||
|
||||
|
||||
2.times do |i|
|
||||
setup { cleanup_count += 1 }
|
||||
teardown { cleanup_count -= 1 }
|
||||
end
|
||||
|
||||
|
||||
2.times do |i|
|
||||
should "also call all setups and all teardowns in parent and subcontext (check ##{i + 1})" do
|
||||
assert_equal 4, cleanup_count
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
should_eventually "pass, since it's unimplemented" do
|
||||
flunk "what?"
|
||||
end
|
||||
|
||||
should_eventually "not require a block when using should_eventually"
|
||||
should "pass without a block, as that causes it to piggyback to should_eventually"
|
||||
|
||||
|
||||
context "context for testing should piggybacking" do
|
||||
should "call should_eventually as we are not passing a block"
|
||||
end
|
||||
|
@ -164,7 +164,7 @@ class ContextTest < ActiveSupport::TestCase # :nodoc:
|
|||
should "return the result of the block as the subject" do
|
||||
assert_equal @expected, subject
|
||||
end
|
||||
|
||||
|
||||
context "nested context block without a subject block" do
|
||||
should "return the result of the parent context's subject block" do
|
||||
assert_equal @expected, subject
|
||||
|
|
|
@ -41,7 +41,7 @@ class ConvertToShouldSyntaxTest < ActiveSupport::TestCase # :nodoc:
|
|||
|
||||
end
|
||||
EOS
|
||||
|
||||
|
||||
FIXTURE_PATH = "./convert_to_should_syntax_fixture.dat"
|
||||
|
||||
RUBY = ENV['RUBY'] || 'ruby'
|
||||
|
|
|
@ -22,7 +22,7 @@ class PrivateHelpersTest < ActiveSupport::TestCase # :nodoc:
|
|||
get_options!(args, :one)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
should "return single wanted option" do
|
||||
args = [:a, :b, {:class => Object}]
|
||||
klass = get_options!(args,:class)
|
||||
|
|
|
@ -4,11 +4,11 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|||
should "be able to define a should statement outside of a context" do
|
||||
assert true
|
||||
end
|
||||
|
||||
|
||||
should "see the name of my class as ShouldTest" do
|
||||
assert_equal "ShouldTest", self.class.name
|
||||
end
|
||||
|
||||
|
||||
def self.should_see_class_methods
|
||||
should "be able to see class methods" do
|
||||
assert true
|
||||
|
@ -27,13 +27,13 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|||
|
||||
def self.should_see_blah
|
||||
should "see @blah through a macro" do
|
||||
assert @blah
|
||||
assert @blah
|
||||
end
|
||||
end
|
||||
|
||||
def self.should_not_see_blah
|
||||
should "not see @blah through a macro" do
|
||||
assert_nil @blah
|
||||
assert_nil @blah
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -75,12 +75,12 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|||
setup do
|
||||
@blah = "blah"
|
||||
end
|
||||
|
||||
|
||||
should "have @blah == 'blah'" do
|
||||
assert_equal "blah", @blah
|
||||
end
|
||||
should_see_blah
|
||||
|
||||
|
||||
should "have name set right" do
|
||||
assert_match(/^test: Context with setup block/, self.to_s)
|
||||
end
|
||||
|
@ -89,11 +89,11 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|||
setup do
|
||||
@blah = "#{@blah} twice"
|
||||
end
|
||||
|
||||
|
||||
should "be named correctly" do
|
||||
assert_match(/^test: Context with setup block and a subcontext should be named correctly/, self.to_s)
|
||||
end
|
||||
|
||||
|
||||
should "run the setup methods in order" do
|
||||
assert_equal @blah, "blah twice"
|
||||
end
|
||||
|
@ -105,7 +105,7 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|||
setup do
|
||||
@blah = "foo"
|
||||
end
|
||||
|
||||
|
||||
should "have @blah == 'foo'" do
|
||||
assert_equal "foo", @blah
|
||||
end
|
||||
|
@ -115,7 +115,7 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|||
end
|
||||
should_see_blah
|
||||
end
|
||||
|
||||
|
||||
should_eventually "pass, since it's a should_eventually" do
|
||||
flunk "what?"
|
||||
end
|
||||
|
@ -152,7 +152,7 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|||
should "be good" do; end
|
||||
should "another" do; end
|
||||
end
|
||||
|
||||
|
||||
names = context.shoulds.map {|s| s[:name]}
|
||||
assert_equal ["another", "be good"], names.sort
|
||||
end
|
||||
|
@ -164,7 +164,7 @@ class ShouldTest < ActiveSupport::TestCase # :nodoc:
|
|||
setup do; "setup"; end
|
||||
teardown do; "teardown"; end
|
||||
end
|
||||
|
||||
|
||||
assert_equal "setup", context.setup_blocks.first.call
|
||||
assert_equal "teardown", context.teardown_blocks.first.call
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class ActiveSupport::TestCase
|
||||
class ActiveSupport::TestCase
|
||||
|
||||
TMP_VIEW_PATH =
|
||||
File.expand_path(File.join(File.dirname(__FILE__), 'rails2_root', 'tmp', 'views')).freeze
|
||||
|
||||
def create_table(table_name, &block)
|
||||
connection = ActiveRecord::Base.connection
|
||||
|
||||
|
||||
begin
|
||||
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
||||
connection.create_table(table_name, &block)
|
||||
|
@ -77,7 +77,7 @@ class ActiveSupport::TestCase
|
|||
klass = define_controller('Examples')
|
||||
block ||= lambda { render :nothing => true }
|
||||
klass.class_eval { define_method(action, &block) }
|
||||
define_routes do |map|
|
||||
define_routes do |map|
|
||||
map.connect 'examples', :controller => 'examples', :action => action
|
||||
end
|
||||
|
||||
|
@ -100,7 +100,7 @@ class ActiveSupport::TestCase
|
|||
|
||||
def teardown_with_models
|
||||
if @defined_constants
|
||||
@defined_constants.each do |class_name|
|
||||
@defined_constants.each do |class_name|
|
||||
Object.send(:remove_const, class_name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class ActiveSupport::TestCase
|
||||
class ActiveSupport::TestCase
|
||||
|
||||
TMP_VIEW_PATH =
|
||||
File.expand_path(File.join(File.dirname(__FILE__), 'rails3_root', 'tmp', 'views')).freeze
|
||||
|
||||
def create_table(table_name, &block)
|
||||
connection = ActiveRecord::Base.connection
|
||||
|
||||
|
||||
begin
|
||||
connection.execute("DROP TABLE IF EXISTS #{table_name}")
|
||||
connection.create_table(table_name, &block)
|
||||
|
@ -69,7 +69,7 @@ class ActiveSupport::TestCase
|
|||
klass = define_controller('Examples')
|
||||
block ||= lambda { render :nothing => true }
|
||||
klass.class_eval { layout false; define_method(action, &block) }
|
||||
define_routes do |map|
|
||||
define_routes do |map|
|
||||
map.connect 'examples', :controller => 'examples', :action => action
|
||||
end
|
||||
|
||||
|
@ -94,7 +94,7 @@ class ActiveSupport::TestCase
|
|||
|
||||
def teardown_with_models
|
||||
if @defined_constants
|
||||
@defined_constants.each do |class_name|
|
||||
@defined_constants.each do |class_name|
|
||||
Object.send(:remove_const, class_name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ class FleaTest < ActiveSupport::TestCase
|
|||
should_have_and_belong_to_many :dogs
|
||||
|
||||
context "when a flea is created" do
|
||||
setup do
|
||||
setup do
|
||||
Flea.create
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue