Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

some whitespace cleanup

  • Loading branch information...
commit 67d8d8403b0f15d3fec07b86e549af4543211773 1 parent 3510419
@dchelimsky authored
View
12 lib/autotest/rspec.rb
@@ -4,13 +4,13 @@
at.clear_mappings
# watch out: Ruby bug (1.8.6):
# %r(/) != /\//
- at.add_mapping(%r%^spec/.*_spec.rb$%) { |filename, _|
- filename
+ at.add_mapping(%r%^spec/.*_spec.rb$%) { |filename, _|
+ filename
}
- at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
+ at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
["spec/#{m[1]}_spec.rb"]
}
- at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
+ at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
at.files_matching %r%^spec/.*_spec\.rb$%
}
end
@@ -24,7 +24,7 @@ def initialize
self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
end
-
+
def consolidate_failures(failed)
filters = new_hash_of_arrays
failed.each do |spec, trace|
@@ -40,7 +40,7 @@ def make_test_cmd(files_to_test)
spec_program = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec'))
return "#{ruby} #{spec_program} --autospec #{files_to_test.keys.flatten.join(' ')} #{add_options_if_present}"
end
-
+
def add_options_if_present # :nodoc:
File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
end
View
2  lib/spec/autorun.rb
@@ -1,3 +1,3 @@
require 'spec'
-Spec::Runner.autorun
+Spec::Runner.autorun
View
6 lib/spec/deprecation.rb
@@ -16,15 +16,15 @@ def deprecate(method, alternate_method=nil)
* please use #{alternate_method} instead.
ADDITIONAL
end
-
+
message << "*****************************************************************"
warn(message)
end
-
+
def warn(message)
Kernel.warn(message)
end
-
+
end
class HashWithDeprecationNotice < Hash
View
1  lib/spec/dsl.rb
@@ -1,2 +1 @@
require 'spec/dsl/main'
-
View
12 lib/spec/dsl/main.rb
@@ -2,7 +2,7 @@ module Spec
module DSL
module Main
include Spec::Example::ArgsAndOptions
-
+
# Creates and returns a class that includes the ExampleGroupMethods
# module. Which ExampleGroup type is created depends on the directory of the file
# calling this method. For example, Spec::Rails will use different
@@ -28,7 +28,7 @@ def describe(*args, &block)
Spec::Example::ExampleGroupFactory.create_example_group(*args, &block)
end
alias :context :describe
-
+
# Creates an example group that can be shared by other example groups
#
# == Examples
@@ -39,7 +39,7 @@ def describe(*args, &block)
#
# describe SmallEdition do
# it_should_behave_like "All Editions"
- #
+ #
# it "should do small edition stuff" do
# ...
# end
@@ -50,7 +50,7 @@ def share_examples_for(*args, &block)
Spec::Example::ExampleGroupFactory.create_shared_example_group(*args, &block)
end
alias :shared_examples_for :share_examples_for
-
+
# Creates a Shared Example Group and assigns it to a constant
#
# share_as :AllEditions do
@@ -59,7 +59,7 @@ def share_examples_for(*args, &block)
#
# describe SmallEdition do
# it_should_behave_like AllEditions
- #
+ #
# it "should do small edition stuff" do
# ...
# end
@@ -70,7 +70,7 @@ def share_examples_for(*args, &block)
#
# describe SmallEdition do
# include AllEditions
- #
+ #
# it "should do small edition stuff" do
# ...
# end
View
57 lib/spec/example.rb
@@ -7,102 +7,102 @@ module Spec
# An Example Group is a group of code examples.
#
# RSpec exposes a DSL to describe groups of examples.
- #
+ #
# describe Account do
# it "should have a balance of $0" do
# account = Account.new
# account.balance.should == Money.new(0, :dollars)
# end
# end
- #
+ #
# == Before and After
- #
+ #
# You can use the <tt>before()</tt> and <tt>after()</tt> methods to extract
# common code within an Example Group. Both methods take an optional scope
# argument so you can run the block before :each example or before :all
# examples
- #
+ #
# describe "..." do
# before :all do
# ...
# end
- #
+ #
# before :each do
# ...
# end
- #
+ #
# it "should do something" do
# ...
# end
- #
+ #
# it "should do something else" do
# ...
# end
- #
+ #
# after :each do
# ...
# end
- #
+ #
# after :all do
# ...
# end
- #
+ #
# end
- #
+ #
# The <tt>before :each</tt> block will run before each of the examples, once
# for each example. Likewise, the <tt>after :each</tt> block will run after
# each of the examples.
- #
+ #
# It is also possible to specify a <tt>before :all</tt> and <tt>after
# :all</tt> block that will run only once for each example group, before the
# first <code>before :each</code> and after the last <code>after
# :each</code> respectively. The use of these is generally discouraged,
# because it introduces dependencies between the examples. Still, it might
# prove useful for very expensive operations if you know what you are doing.
- #
+ #
# == Local helper methods
- #
+ #
# You can include local helper methods by simply expressing them within an
# example group:
- #
+ #
# describe "..." do
- #
+ #
# it "..." do
# helper_method
# end
- #
+ #
# def helper_method
# ...
# end
- #
+ #
# end
- #
+ #
# == Included helper methods
- #
+ #
# You can include helper methods in multiple example groups by expressing
# them within a module, and then including that module in your example
# groups:
- #
+ #
# module AccountExampleHelperMethods
# def helper_method
# ...
# end
# end
- #
+ #
# describe "A new account" do
# include AccountExampleHelperMethods
# before do
# @account = Account.new
# end
- #
+ #
# it "should have a balance of $0" do
# helper_method
# @account.balance.should eql(Money.new(0, :dollars))
# end
# end
- #
+ #
# == Shared Example Groups
- #
+ #
# You can define a shared example group, that may be used on other groups
#
# share_examples_for "All Editions" do
@@ -111,7 +111,7 @@ module Spec
#
# describe SmallEdition do
# it_should_behave_like "All Editions"
- #
+ #
# it "should do small edition stuff" do
# ...
# end
@@ -125,7 +125,7 @@ module Spec
#
# describe SmallEdition do
# it_should_behave_like AllEditions
- #
+ #
# it "should do small edition stuff" do
# ...
# end
@@ -136,7 +136,7 @@ module Spec
#
# describe SmallEdition do
# include AllEditions
- #
+ #
# it "should do small edition stuff" do
# ...
# end
@@ -162,4 +162,3 @@ module Example
require 'spec/example/example_group_factory'
require 'spec/example/errors'
require 'spec/example/example_matcher'
-
View
2  lib/spec/example/args_and_options.rb
@@ -12,7 +12,7 @@ def add_options(args, options={}) # :nodoc:
args.options.merge!(options)
args.options
end
-
+
def set_location(options, location) # :nodoc:
options[:location] ||= location
end
View
20 lib/spec/example/before_and_after_hooks.rb
@@ -5,12 +5,12 @@ class << self
def before_suite_parts # :nodoc:
@before_suite_parts ||= []
end
-
+
def after_suite_parts # :nodoc:
@after_suite_parts ||= []
end
end
-
+
# Registers a block to be executed before examples. <tt>scope</tt> can be
# <tt>:each</tt> (default), <tt>:all</tt>, or <tt>:suite</tt>. When
# <tt>:each</tt>, the block is executed before each example. When
@@ -23,7 +23,7 @@ def append_before(scope = :each, &block)
# Registers a block to be executed before each example.
# This method prepends +block+ to existing before blocks.
- #
+ #
# See <tt>append_before</tt> for scoping semantics.
def prepend_before(scope = :each, &block)
before_parts(scope).unshift(block)
@@ -31,7 +31,7 @@ def prepend_before(scope = :each, &block)
# Registers a block to be executed after each example.
# This method prepends +block+ to existing after blocks.
- #
+ #
# See <tt>append_before</tt> for scoping semantics.
def prepend_after(scope = :each, &block)
after_parts(scope).unshift(block)
@@ -40,7 +40,7 @@ def prepend_after(scope = :each, &block)
# Registers a block to be executed after each example.
# This method appends +block+ to existing after blocks.
- #
+ #
# See <tt>append_before</tt> for scoping semantics.
def append_after(scope = :each, &block)
after_parts(scope) << block
@@ -53,7 +53,7 @@ def before_each_parts # :nodoc:
def after_each_parts # :nodoc:
@after_each_parts ||= []
end
-
+
def before_all_parts # :nodoc:
@before_all_parts ||= []
end
@@ -65,13 +65,13 @@ def after_all_parts # :nodoc:
def before_suite_parts # :nodoc:
BeforeAndAfterHooks.before_suite_parts
end
-
+
def after_suite_parts # :nodoc:
BeforeAndAfterHooks.after_suite_parts
end
-
+
private
-
+
def before_parts(scope)
case scope
when :each; before_each_parts
@@ -90,4 +90,4 @@ def after_parts(scope)
end
end
-end
+end
View
4 lib/spec/example/errors.rb
@@ -1,7 +1,7 @@
module Spec
module Example
class ExamplePendingError < StandardError; end
-
+
class NotYetImplementedError < ExamplePendingError
MESSAGE = "Not Yet Implemented"
def initialize
@@ -10,7 +10,7 @@ def initialize
end
class PendingExampleFixedError < StandardError; end
-
+
class NoDescriptionError < ArgumentError
def initialize(kind, location)
super("No description supplied for #{kind} declared on #{location}")
View
1  lib/spec/example/example_group.rb
@@ -8,4 +8,3 @@ class ExampleGroup
end
end
end
-
View
6 lib/spec/example/example_group_factory.rb
@@ -1,10 +1,10 @@
module Spec
module Example
-
+
class ExampleGroupFactory
module ClassMethods
include Spec::Example::ArgsAndOptions
-
+
def reset
@example_group_types = nil
default(ExampleGroup)
@@ -23,7 +23,7 @@ def register_example_group(klass)
def create_shared_example_group(*args, &example_group_block) # :nodoc:
::Spec::Example::SharedExampleGroup.register(*args, &example_group_block)
end
-
+
def create_example_group(*args, &block)
raise ArgumentError if args.empty? || block.nil?
add_options(args)
View
20 lib/spec/example/example_group_hierarchy.rb
@@ -8,43 +8,43 @@ def initialize(example_group_class)
flatten!
end
end
-
+
def run_before_all(example)
example.eval_each_fail_fast(before_all_parts)
end
-
+
def run_before_each(example)
example.eval_each_fail_fast(before_each_parts)
end
-
+
def run_after_each(example)
example.eval_each_fail_slow(after_each_parts)
end
-
+
def run_after_all(example)
example.eval_each_fail_slow(after_all_parts)
end
-
+
def before_all_parts
@before_all_parts ||= collect {|klass| klass.before_all_parts}.flatten
end
-
+
def before_each_parts
@before_each_parts ||= collect {|klass| klass.before_each_parts}.flatten
end
-
+
def after_each_parts
@after_each_parts ||= reverse.collect {|klass| klass.after_each_parts}.flatten
end
-
+
def after_all_parts
@after_all_parts ||= reverse.collect {|klass| klass.after_all_parts}.flatten
end
-
+
def nested_descriptions
@nested_descriptions ||= collect {|eg| nested_description_from(eg) == "" ? nil : nested_description_from(eg) }.compact
end
-
+
def nested_description_from(example_group)
example_group.description_args.join
end
View
50 lib/spec/example/example_group_methods.rb
@@ -1,7 +1,7 @@
module Spec
module Example
- module ExampleGroupMethods
+ module ExampleGroupMethods
class << self
attr_accessor :matcher_class
@@ -20,16 +20,16 @@ def build_description_from(*args)
include Spec::Example::ArgsAndOptions
attr_reader :location
-
+
def options # :nodoc:
@options ||= {}
end
-
+
def inherited(klass) # :nodoc:
super
ExampleGroupFactory.register_example_group(klass)
end
-
+
# Makes the describe/it syntax available from a class. For example:
#
# class StackSpec < Spec::ExampleGroup
@@ -59,14 +59,14 @@ def describe(*args, &example_group_block)
end
end
alias :context :describe
-
+
# Use this to pull in examples from shared example groups.
def it_should_behave_like(*shared_example_groups)
shared_example_groups.each do |group|
include_shared_example_group(group)
end
end
-
+
# Creates an instance of the current example group class and adds it to
# a collection of examples of the current example group.
def example(description=nil, options={}, backtrace=nil, &implementation)
@@ -75,7 +75,7 @@ def example(description=nil, options={}, backtrace=nil, &implementation)
example_implementations[example_proxy] = implementation || pending_implementation
example_proxy
end
-
+
def pending_implementation
lambda { raise(Spec::Example::NotYetImplementedError) }
end
@@ -87,10 +87,10 @@ def pending_implementation
def xexample(description=nil, opts={}, &block)
Kernel.warn("Example disabled: #{description}")
end
-
+
alias_method :xit, :xexample
alias_method :xspecify, :xexample
-
+
def run(run_options)
examples = examples_to_run(run_options)
notify(run_options.reporter) unless examples.empty?
@@ -110,7 +110,7 @@ def set_description(*args)
@location = File.expand_path(options[:location]) if options[:location]
self
end
-
+
def notify(reporter) # :nodoc:
reporter.example_group_started(ExampleGroupProxy.new(self))
end
@@ -118,33 +118,33 @@ def notify(reporter) # :nodoc:
def description
@description ||= ExampleGroupMethods.build_description_from(*description_parts) || to_s
end
-
+
def described_type
@described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)}
end
-
+
def described_class
@described_class ||= Class === described_type ? described_type : nil
end
-
+
def description_args
@description_args ||= []
end
-
+
def description_parts #:nodoc:
@description_parts ||= example_group_hierarchy.inject([]) do |parts, example_group_class|
[parts << example_group_class.description_args].flatten
end
end
-
+
def example_proxies # :nodoc:
@example_proxies ||= []
end
-
+
def example_implementations # :nodoc:
@example_implementations ||= {}
end
-
+
def examples(run_options=nil) #:nodoc:
(run_options && run_options.reverse) ? example_proxies.reverse : example_proxies
end
@@ -156,15 +156,15 @@ def number_of_examples #:nodoc:
def example_group_hierarchy
@example_group_hierarchy ||= ExampleGroupHierarchy.new(self)
end
-
+
def nested_descriptions
example_group_hierarchy.nested_descriptions
end
-
+
def include_constants_in(mod)
include mod if (Spec::Ruby.version.to_f >= 1.9) & (Module === mod) & !(Class === mod)
end
-
+
private
def subclass(*args, &example_group_block)
@@ -201,16 +201,16 @@ def run_examples(success, instance_variables, examples, run_options)
return [success, instance_variables] unless success
after_all_instance_variables = instance_variables
-
+
examples.each do |example|
example_group_instance = new(example, &example_implementations[example])
success &= example_group_instance.execute(run_options, instance_variables)
after_all_instance_variables = example_group_instance.instance_variable_hash
end
-
+
return [success, after_all_instance_variables]
end
-
+
def run_after_all(success, instance_variables, run_options)
return success if example_group_hierarchy.after_all_parts.empty?
example_proxy = ExampleProxy.new("after(:all)")
@@ -222,7 +222,7 @@ def run_after_all(success, instance_variables, run_options)
run_options.reporter.example_failed(example_proxy, e)
false
end
-
+
def examples_to_run(run_options)
return example_proxies unless examples_were_specified?(run_options)
example_proxies.reject do |proxy|
@@ -239,7 +239,7 @@ def examples_were_specified?(run_options)
def method_added(name) # :nodoc:
example(name.to_s, {}, caller(0)[1]) {__send__ name.to_s} if example_method?(name.to_s)
end
-
+
def example_method?(method_name)
should_method?(method_name)
end
View
19 lib/spec/example/example_group_proxy.rb
@@ -3,7 +3,7 @@ module Example
# Lightweight proxy for an example group. This is the object that is passed
# to Spec::Runner::Formatter::BaseFormatter#example_group_started
class ExampleGroupProxy
-
+
def initialize(example_group) # :nodoc:
@description = example_group.description
@nested_descriptions = example_group.nested_descriptions
@@ -14,35 +14,35 @@ def initialize(example_group) # :nodoc:
@options.delete(:location)
@options.delete(:scope)
end
-
+
# Optional hash passed to the example group declaration. Note that RSpec uses
# this hash internally and reserves the keys :location and :scope for its own
# use (and removes them from this hash)
attr_reader :options
-
+
# This is the description passed to the <tt>describe()</tt> method or any
# of its aliases
attr_reader :description
-
+
# Used by Spec::Runner::Formatter::NestedTextFormatter to access the
# description of each example group in a nested group separately.
attr_reader :nested_descriptions
-
+
# A collection of ExampleGroupProxy objects, one for each example
# declared in this group.
attr_reader :examples
-
+
# The file and line number at which the proxied example group
# was declared. This is extracted from <tt>caller</tt>, and is therefore
# formatted as an individual line in a backtrace.
attr_reader :location
-
+
# Deprecated - use location() instead
def backtrace
Spec::deprecate("ExampleGroupProxy#backtrace","ExampleGroupProxy#location")
@backtrace
end
-
+
# Deprecated - just use gsub on the description instead.
def filtered_description(regexp)
Spec::deprecate("ExampleGroupProxy#filtered_description","gsub (or similar) to modify ExampleGroupProxy#description")
@@ -52,11 +52,10 @@ def filtered_description(regexp)
end
)
end
-
+
def ==(other) # :nodoc:
other.description == description
end
end
end
end
-
View
4 lib/spec/example/example_matcher.rb
@@ -5,13 +5,13 @@ def initialize(example_group_description, example_name)
@example_group_description = example_group_description
@example_name = example_name
end
-
+
def matches?(specified_examples)
specified_examples.any? do |specified_example|
matches_literal_example?(specified_example) || matches_example_not_considering_modules?(specified_example)
end
end
-
+
protected
def matches_literal_example?(specified_example)
specified_example =~ /(^#{example_group_regex} #{example_regexp}$|^#{example_group_regex}$|^#{example_group_with_before_all_regexp}$|^#{example_regexp}$)/
View
20 lib/spec/example/example_methods.rb
@@ -1,10 +1,10 @@
module Spec
module Example
module ExampleMethods
-
+
extend Spec::Example::ModuleReopeningFix
include Spec::Example::Subject::ExampleMethods
-
+
def violated(message="")
raise Spec::Expectations::ExpectationNotMetError.new(message)
end
@@ -24,7 +24,7 @@ def description
raise Spec::Example::NoDescriptionError.new("example", @_proxy.location)
end
end
-
+
def options # :nodoc:
@_proxy.options
end
@@ -32,7 +32,7 @@ def options # :nodoc:
def execute(run_options, instance_variables) # :nodoc:
run_options.reporter.example_started(@_proxy)
set_instance_variables_from_hash(instance_variables)
-
+
execution_error = nil
Timeout.timeout(run_options.timeout) do
begin
@@ -51,12 +51,12 @@ def execute(run_options, instance_variables) # :nodoc:
run_options.reporter.example_finished(@_proxy.update(description), execution_error)
success = execution_error.nil? || ExamplePendingError === execution_error
end
-
+
module BlockAliases
alias_method :to, :should
alias_method :to_not, :should_not
end
-
+
# Extends the submitted block with aliases to and to_not
# for should and should_not. Allows expectations like this:
#
@@ -115,10 +115,10 @@ def initialize(example_proxy, &implementation)
end
private
-
+
include Matchers
include Pending
-
+
def before_each_example
setup_mocks_for_rspec
run_before_each
@@ -134,7 +134,7 @@ def after_each_example
def described_class
self.class.described_class
end
-
+
def description_args
self.class.description_args
end
@@ -142,7 +142,7 @@ def description_args
def example_group_hierarchy
self.class.example_group_hierarchy
end
-
+
end
end
end
View
10 lib/spec/example/example_proxy.rb
@@ -7,32 +7,32 @@ class ExampleProxy
def initialize(description=nil, options={}, location=nil) # :nodoc:
@description, @options, @location = description, options, location
end
-
+
# Optional hash passed to the example declaration
attr_reader :options
# This is the docstring passed to the <tt>it()</tt> method or any
# of its aliases
attr_reader :description
-
+
# The file and line number at which the represented example
# was declared. This is extracted from <tt>caller</tt>, and is therefore
# formatted as an individual line in a backtrace.
attr_reader :location
-
+
# Deprecated - use location()
def backtrace
Spec.deprecate("ExampleProxy#backtrace","ExampleProxy#location")
location
end
-
+
# Convenience method for example group - updates the value of
# <tt>description</tt> and returns self.
def update(description) # :nodoc:
@description = description
self
end
-
+
def ==(other) # :nodoc:
(other.description == description) & (other.location == location)
end
View
14 lib/spec/example/module_reopening_fix.rb
@@ -2,23 +2,23 @@ module Spec
module Example
# When you reopen a module that is included in another module that is included in a class,
# the new material you define does not make it to the class. This fixes that.
- #
+ #
# == Example
- #
+ #
# module M1; end
- #
+ #
# module M2
# def foo; "FOO"; end
# end
- #
+ #
# class C
# include M1
# end
- #
+ #
# module M1
# include M2
# end
- #
+ #
# c = C.new
# c.foo
# NoMethodError: undefined method `foo' for #<C:0x5e89a4>
@@ -40,4 +40,4 @@ def include(mod)
end
end
end
-end
+end
View
2  lib/spec/example/pending.rb
@@ -1,5 +1,5 @@
module Spec
- module Example
+ module Example
module Pending
def pending(message = "TODO")
if block_given?
View
1  lib/spec/example/predicate_matchers.rb
@@ -44,4 +44,3 @@ def define_methods_from_predicate_matchers # :nodoc:
end
end
end
-
View
10 lib/spec/example/shared_example_group.rb
@@ -7,7 +7,7 @@ def register(*args, &block)
shared_example_groups << new_example_group unless already_registered?(new_example_group)
new_example_group
end
-
+
def find(example_group_description)
shared_example_groups.find {|b| b.description == example_group_description}
end
@@ -15,21 +15,21 @@ def find(example_group_description)
def clear
shared_example_groups.clear
end
-
+
def include?(group)
shared_example_groups.include?(group)
end
-
+
def count
shared_example_groups.length
end
private
-
+
def shared_example_groups
@shared_example_groups ||= []
end
-
+
def already_registered?(new_example_group)
existing_example_group = find(new_example_group.description)
return false unless existing_example_group
View
14 lib/spec/example/subject.rb
@@ -18,11 +18,11 @@ def subject(&block)
block.nil? ?
explicit_subject || implicit_subject : @explicit_subject_block = block
end
-
+
attr_reader :explicit_subject_block # :nodoc:
-
+
private
-
+
def explicit_subject
group = self
while group.respond_to?(:explicit_subject_block)
@@ -30,12 +30,12 @@ def explicit_subject
group = group.superclass
end
end
-
+
def implicit_subject
(described_class ? lambda {described_class.new} : lambda {description_args.first})
end
end
-
+
module ExampleMethods
alias_method :__should_for_example_group__, :should
@@ -68,7 +68,7 @@ module ExampleMethods
def subject
@subject ||= instance_eval(&self.class.subject)
end
-
+
# When +should+ is called with no explicit receiver, the call is
# delegated to the object returned by +subject+. Combined with
# an implicit subject (see +subject+), this supports very concise
@@ -97,4 +97,4 @@ def should_not(matcher=nil)
end
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.