aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins/rspec/lib
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/plugins/rspec/lib')
-rw-r--r--vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/flexmock.rb24
-rw-r--r--vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/mocha.rb25
-rw-r--r--vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/rr.rb22
-rw-r--r--vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/rspec.rb21
-rw-r--r--vendor/plugins/rspec/lib/spec/autorun.rb3
-rw-r--r--vendor/plugins/rspec/lib/spec/deprecation.rb40
-rw-r--r--vendor/plugins/rspec/lib/spec/dsl.rb1
-rw-r--r--vendor/plugins/rspec/lib/spec/dsl/main.rb92
-rw-r--r--vendor/plugins/rspec/lib/spec/example/args_and_options.rb27
-rw-r--r--vendor/plugins/rspec/lib/spec/example/before_and_after_hooks.rb93
-rw-r--r--vendor/plugins/rspec/lib/spec/example/example_group_hierarchy.rb53
-rw-r--r--vendor/plugins/rspec/lib/spec/example/example_group_proxy.rb61
-rw-r--r--vendor/plugins/rspec/lib/spec/example/example_proxy.rb41
-rw-r--r--vendor/plugins/rspec/lib/spec/example/predicate_matchers.rb46
-rw-r--r--vendor/plugins/rspec/lib/spec/example/subject.rb108
-rw-r--r--vendor/plugins/rspec/lib/spec/expectations/extensions/kernel.rb52
-rw-r--r--vendor/plugins/rspec/lib/spec/expectations/fail_with.rb45
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/be_instance_of.rb26
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/be_kind_of.rb26
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/compatibility.rb14
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/dsl.rb20
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/errors.rb5
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/extensions/instance_exec.rb31
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/generated_descriptions.rb36
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/match_array.rb71
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/matcher.rb87
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/method_missing.rb9
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/pretty.rb37
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers/wrap_expectation.rb55
-rw-r--r--vendor/plugins/rspec/lib/spec/mocks/argument_matchers.rb237
-rw-r--r--vendor/plugins/rspec/lib/spec/mocks/example_methods.rb69
-rw-r--r--vendor/plugins/rspec/lib/spec/ruby.rb9
-rw-r--r--vendor/plugins/rspec/lib/spec/runner/configuration.rb194
-rw-r--r--vendor/plugins/rspec/lib/spec/runner/differs/default.rb93
-rw-r--r--vendor/plugins/rspec/lib/spec/runner/differs/load-diff-lcs.rb12
-rw-r--r--vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb9
-rw-r--r--vendor/plugins/rspec/lib/spec/runner/formatter/no_op_method_missing.rb21
-rw-r--r--vendor/plugins/rspec/lib/spec/runner/formatter/silent_formatter.rb10
-rw-r--r--vendor/plugins/rspec/lib/spec/runner/line_number_query.rb78
-rw-r--r--vendor/plugins/rspec/lib/spec/stubs/cucumber.rb5
-rw-r--r--vendor/plugins/rspec/lib/spec/test/unit.rb10
41 files changed, 1918 insertions, 0 deletions
diff --git a/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/flexmock.rb b/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/flexmock.rb
new file mode 100644
index 000000000..18dd453dd
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/flexmock.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+#
+# Created by Jim Weirich on 2007-04-10.
+# Copyright (c) 2007. All rights reserved.
+
+require 'rubygems' unless ENV['NO_RUBYGEMS']
+require 'flexmock/rspec'
+
+module Spec
+ module Adapters
+ module MockFramework
+ include FlexMock::MockContainer
+ def setup_mocks_for_rspec
+ # No setup required
+ end
+ def verify_mocks_for_rspec
+ flexmock_verify
+ end
+ def teardown_mocks_for_rspec
+ flexmock_close
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/mocha.rb b/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/mocha.rb
new file mode 100644
index 000000000..4c97c139a
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/mocha.rb
@@ -0,0 +1,25 @@
+require 'rubygems' unless ENV['NO_RUBYGEMS']
+require 'mocha/standalone'
+require 'mocha/object'
+
+module Spec
+ module Adapters
+ module MockFramework
+ # Mocha::Standalone was deprecated as of Mocha 0.9.7.
+ begin
+ include Mocha::API
+ rescue NameError
+ include Mocha::Standalone
+ end
+ def setup_mocks_for_rspec
+ mocha_setup
+ end
+ def verify_mocks_for_rspec
+ mocha_verify
+ end
+ def teardown_mocks_for_rspec
+ mocha_teardown
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/rr.rb b/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/rr.rb
new file mode 100644
index 000000000..758ddf611
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/rr.rb
@@ -0,0 +1,22 @@
+require 'rubygems' unless ENV['NO_RUBYGEMS']
+require 'rr'
+
+patterns = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS
+patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
+
+module Spec
+ module Adapters
+ module MockFramework
+ include RR::Extensions::InstanceMethods
+ def setup_mocks_for_rspec
+ RR::Space.instance.reset
+ end
+ def verify_mocks_for_rspec
+ RR::Space.instance.verify_doubles
+ end
+ def teardown_mocks_for_rspec
+ RR::Space.instance.reset
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/rspec.rb b/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/rspec.rb
new file mode 100644
index 000000000..b159f8bfe
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/adapters/mock_frameworks/rspec.rb
@@ -0,0 +1,21 @@
+require 'spec/mocks/framework'
+require 'spec/mocks/extensions'
+
+module Spec
+ module Adapters
+ unless defined?(MockFramework)
+ module MockFramework
+ include Spec::Mocks::ExampleMethods
+ def setup_mocks_for_rspec
+ $rspec_mocks ||= Spec::Mocks::Space.new
+ end
+ def verify_mocks_for_rspec
+ $rspec_mocks.verify_all
+ end
+ def teardown_mocks_for_rspec
+ $rspec_mocks.reset_all
+ end
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/autorun.rb b/vendor/plugins/rspec/lib/spec/autorun.rb
new file mode 100644
index 000000000..f29b81966
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/autorun.rb
@@ -0,0 +1,3 @@
+require 'spec'
+
+Spec::Runner.autorun
diff --git a/vendor/plugins/rspec/lib/spec/deprecation.rb b/vendor/plugins/rspec/lib/spec/deprecation.rb
new file mode 100644
index 000000000..ebab78942
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/deprecation.rb
@@ -0,0 +1,40 @@
+module Spec
+ class << self
+ def deprecate(method, alternate_method=nil)
+ message = <<-NOTICE
+
+*****************************************************************
+DEPRECATION WARNING: you are using deprecated behaviour that will
+be removed from a future version of RSpec.
+
+#{caller(0)[2]}
+
+* #{method} is deprecated.
+NOTICE
+ if alternate_method
+ message << <<-ADDITIONAL
+* please use #{alternate_method} instead.
+ADDITIONAL
+ end
+
+ message << "*****************************************************************"
+ warn(message)
+ end
+
+ def warn(message)
+ Kernel.warn(message)
+ end
+
+ end
+
+ class HashWithDeprecationNotice < Hash
+ def initialize(method, alternate_method=nil, &block)
+ @method, @alternate_method = method, alternate_method
+ end
+ def []=(k,v)
+ Spec.deprecate(@method, @alternate_method)
+ super
+ end
+ end
+end
+
diff --git a/vendor/plugins/rspec/lib/spec/dsl.rb b/vendor/plugins/rspec/lib/spec/dsl.rb
new file mode 100644
index 000000000..d93e90d84
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/dsl.rb
@@ -0,0 +1 @@
+require 'spec/dsl/main'
diff --git a/vendor/plugins/rspec/lib/spec/dsl/main.rb b/vendor/plugins/rspec/lib/spec/dsl/main.rb
new file mode 100644
index 000000000..3459275b4
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/dsl/main.rb
@@ -0,0 +1,92 @@
+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
+ # classes for specs living in <tt>spec/models</tt>,
+ # <tt>spec/helpers</tt>, <tt>spec/views</tt> and
+ # <tt>spec/controllers</tt>.
+ #
+ # It is also possible to override autodiscovery of the example group
+ # type with an options Hash as the last argument:
+ #
+ # describe "name", :type => :something_special do ...
+ #
+ # The reason for using different example group classes is to have different
+ # matcher methods available from within the <tt>describe</tt> block.
+ #
+ # See Spec::Example::ExampleGroupFactory#register for details about how to
+ # register special implementations.
+ #
+ def describe(*args, &block)
+ raise Spec::Example::NoDescriptionError.new("example group", caller(0)[1]) if args.empty?
+ add_options(args, :scope => self)
+ set_location(args.options, caller(0)[1])
+ 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
+ #
+ # share_examples_for "All Editions" do
+ # it "all editions behaviour" ...
+ # end
+ #
+ # describe SmallEdition do
+ # it_should_behave_like "All Editions"
+ #
+ # it "should do small edition stuff" do
+ # ...
+ # end
+ # end
+ def share_examples_for(*args, &block)
+ add_options(args)
+ set_location(args.options, caller(0)[1])
+ 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
+ # it "should do all editions stuff" ...
+ # end
+ #
+ # describe SmallEdition do
+ # it_should_behave_like AllEditions
+ #
+ # it "should do small edition stuff" do
+ # ...
+ # end
+ # end
+ #
+ # And, for those of you who prefer to use something more like Ruby, you
+ # can just include the module directly
+ #
+ # describe SmallEdition do
+ # include AllEditions
+ #
+ # it "should do small edition stuff" do
+ # ...
+ # end
+ # end
+ def share_as(name, &block)
+ begin
+ args = [name]
+ add_options(args)
+ set_location(args.options, caller(0)[1])
+ Object.const_set(name, Spec::Example::ExampleGroupFactory.create_shared_example_group(*args, &block))
+ rescue NameError => e
+ raise NameError.new(e.message + "\nThe first argument to share_as must be a legal name for a constant\n")
+ end
+ end
+ end
+ end
+end
+
+include Spec::DSL::Main
diff --git a/vendor/plugins/rspec/lib/spec/example/args_and_options.rb b/vendor/plugins/rspec/lib/spec/example/args_and_options.rb
new file mode 100644
index 000000000..b74fddd8e
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/example/args_and_options.rb
@@ -0,0 +1,27 @@
+module Spec
+ module Example
+ module ArgsAndOptions
+ def args_and_options(*args) # :nodoc:
+ options = Hash === args.last ? args.pop : {}
+ return args, options
+ end
+
+ def add_options(args, options={}) # :nodoc:
+ args << {} unless Hash === args.last
+ args.extend WithOptions
+ args.options.merge!(options)
+ args.options
+ end
+
+ def set_location(options, location) # :nodoc:
+ options[:location] ||= location
+ end
+
+ module WithOptions # :nodoc:
+ def options
+ last
+ end
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/example/before_and_after_hooks.rb b/vendor/plugins/rspec/lib/spec/example/before_and_after_hooks.rb
new file mode 100644
index 000000000..9f5039d1e
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/example/before_and_after_hooks.rb
@@ -0,0 +1,93 @@
+module Spec
+ module Example
+ module BeforeAndAfterHooks
+ 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
+ # <tt>:all</tt>, the block is executed only once before any examples are
+ # run.
+ def append_before(scope = :each, &block)
+ before_parts(scope) << block
+ end
+ alias_method :before, :append_before
+
+ # 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)
+ end
+
+ # 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)
+ end
+ alias_method :after, :prepend_after
+
+ # 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
+ end
+
+ def before_each_parts # :nodoc:
+ @before_each_parts ||= []
+ end
+
+ def after_each_parts # :nodoc:
+ @after_each_parts ||= []
+ end
+
+ def before_all_parts # :nodoc:
+ @before_all_parts ||= []
+ end
+
+ def after_all_parts # :nodoc:
+ @after_all_parts ||= []
+ end
+
+ 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
+ when :all; before_all_parts
+ when :suite; before_suite_parts
+ end
+ end
+
+ def after_parts(scope)
+ case scope
+ when :each; after_each_parts
+ when :all; after_all_parts
+ when :suite; after_suite_parts
+ end
+ end
+
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/example/example_group_hierarchy.rb b/vendor/plugins/rspec/lib/spec/example/example_group_hierarchy.rb
new file mode 100644
index 000000000..f2c9fb5cd
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/example/example_group_hierarchy.rb
@@ -0,0 +1,53 @@
+module Spec
+ module Example
+ class ExampleGroupHierarchy < Array
+ def initialize(example_group_class)
+ push example_group_class
+ if example_group_class.respond_to?(:superclass) && example_group_class.superclass.respond_to?(:example_group_hierarchy)
+ unshift example_group_class.superclass.example_group_hierarchy
+ 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
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/example/example_group_proxy.rb b/vendor/plugins/rspec/lib/spec/example/example_group_proxy.rb
new file mode 100644
index 000000000..3c258d61f
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/example/example_group_proxy.rb
@@ -0,0 +1,61 @@
+module Spec
+ 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
+ @examples = example_group.example_proxies
+ @location = example_group.location
+ @backtrace = example_group.location # deprecated - see the backtrace method below
+ @options = example_group.options.dup
+ @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")
+ ExampleGroupMethods.build_description_from(
+ *nested_descriptions.collect do |description|
+ description =~ regexp ? description.gsub($1, "") : description
+ end
+ )
+ end
+
+ def ==(other) # :nodoc:
+ other.description == description
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/example/example_proxy.rb b/vendor/plugins/rspec/lib/spec/example/example_proxy.rb
new file mode 100644
index 000000000..f726d0e70
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/example/example_proxy.rb
@@ -0,0 +1,41 @@
+module Spec
+ module Example
+ # Lightweight proxy for an example. This is the object that is passed to
+ # example-related methods in Spec::Runner::Formatter::BaseFormatter
+ 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
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/example/predicate_matchers.rb b/vendor/plugins/rspec/lib/spec/example/predicate_matchers.rb
new file mode 100644
index 000000000..c3c319519
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/example/predicate_matchers.rb
@@ -0,0 +1,46 @@
+module Spec
+ module Example
+ module PredicateMatchers
+ # :call-seq:
+ # predicate_matchers[matcher_name] = method_on_object
+ # predicate_matchers[matcher_name] = [method1_on_object, method2_on_object]
+ #
+ # Dynamically generates a custom matcher that will match
+ # a predicate on your class. RSpec provides a couple of these
+ # out of the box:
+ #
+ # exist (for state expectations)
+ # File.should exist("path/to/file")
+ #
+ # an_instance_of (for mock argument matchers)
+ # mock.should_receive(:message).with(an_instance_of(String))
+ #
+ # == Examples
+ #
+ # class Fish
+ # def can_swim?
+ # true
+ # end
+ # end
+ #
+ # describe Fish do
+ # predicate_matchers[:swim] = :can_swim?
+ # it "should swim" do
+ # Fish.new.should swim
+ # end
+ # end
+ def predicate_matchers
+ @predicate_matchers ||= Spec::HashWithDeprecationNotice.new("predicate_matchers", "the new Matcher DSL")
+ end
+
+ def define_methods_from_predicate_matchers # :nodoc:
+ predicate_matchers.each_pair do |matcher_method, method_on_object|
+ define_method matcher_method do |*args|
+ eval("be_#{method_on_object.to_s.gsub('?','')}(*args)")
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/example/subject.rb b/vendor/plugins/rspec/lib/spec/example/subject.rb
new file mode 100644
index 000000000..944edca45
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/example/subject.rb
@@ -0,0 +1,108 @@
+module Spec
+ module Example
+ module Subject
+ module ExampleGroupMethods
+ # Defines an explicit subject for an example group which can then be the
+ # implicit receiver (through delegation) of calls to +should+.
+ #
+ # == Examples
+ #
+ # describe CheckingAccount, "with $50" do
+ # subject { CheckingAccount.new(:amount => 50, :currency => :USD) }
+ # it { should have_a_balance_of(50, :USD) }
+ # it { should_not be_overdrawn }
+ # its(:currency) { should == :USD }
+ # end
+ #
+ # See +ExampleMethods#should+ for more information about this approach.
+ def subject(&block)
+ block.nil? ?
+ explicit_subject || implicit_subject : @explicit_subject_block = block
+ end
+
+ def its(attribute, &block)
+ describe(attribute) do
+ define_method(:subject) { super().send(attribute) }
+ it(&block)
+ end
+ end
+
+ attr_reader :explicit_subject_block # :nodoc:
+
+ private
+
+ def explicit_subject
+ group = self
+ while group.respond_to?(:explicit_subject_block)
+ return group.explicit_subject_block if group.explicit_subject_block
+ 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
+ alias_method :__should_not_for_example_group__, :should_not
+
+ # Returns the subject defined in ExampleGroupMethods#subject. The
+ # subject block is only executed once per example, the result of which
+ # is cached and returned by any subsequent calls to +subject+.
+ #
+ # If a class is passed to +describe+ and no subject is explicitly
+ # declared in the example group, then +subject+ will return a new
+ # instance of that class.
+ #
+ # == Examples
+ #
+ # # explicit subject defined by the subject method
+ # describe Person do
+ # subject { Person.new(:birthdate => 19.years.ago) }
+ # it "should be eligible to vote" do
+ # subject.should be_eligible_to_vote
+ # end
+ # end
+ #
+ # # implicit subject => { Person.new }
+ # describe Person do
+ # it "should be eligible to vote" do
+ # subject.should be_eligible_to_vote
+ # end
+ # end
+ 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
+ # expressions.
+ #
+ # == Examples
+ #
+ # describe Person do
+ # it { should be_eligible_to_vote }
+ # end
+ def should(matcher=nil, message=nil)
+ self == subject ? self.__should_for_example_group__(matcher) : subject.should(matcher,message)
+ end
+
+ # Just like +should+, +should_not+ delegates to the subject (implicit or
+ # explicit) of the example group.
+ #
+ # == Examples
+ #
+ # describe Person do
+ # it { should_not be_eligible_to_vote }
+ # end
+ def should_not(matcher=nil, message=nil)
+ self == subject ? self.__should_not_for_example_group__(matcher) : subject.should_not(matcher,message)
+ end
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/expectations/extensions/kernel.rb b/vendor/plugins/rspec/lib/spec/expectations/extensions/kernel.rb
new file mode 100644
index 000000000..7d8849226
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/expectations/extensions/kernel.rb
@@ -0,0 +1,52 @@
+module Kernel
+ # :call-seq:
+ # should(matcher)
+ # should == expected
+ # should === expected
+ # should =~ expected
+ #
+ # receiver.should(matcher)
+ # => Passes if matcher.matches?(receiver)
+ #
+ # receiver.should == expected #any value
+ # => Passes if (receiver == expected)
+ #
+ # receiver.should === expected #any value
+ # => Passes if (receiver === expected)
+ #
+ # receiver.should =~ regexp
+ # => Passes if (receiver =~ regexp)
+ #
+ # See Spec::Matchers for more information about matchers
+ #
+ # == Warning
+ #
+ # NOTE that this does NOT support receiver.should != expected.
+ # Instead, use receiver.should_not == expected
+ def should(matcher=nil, message=nil, &block)
+ Spec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
+ end
+
+ # :call-seq:
+ # should_not(matcher)
+ # should_not == expected
+ # should_not === expected
+ # should_not =~ expected
+ #
+ # receiver.should_not(matcher)
+ # => Passes unless matcher.matches?(receiver)
+ #
+ # receiver.should_not == expected
+ # => Passes unless (receiver == expected)
+ #
+ # receiver.should_not === expected
+ # => Passes unless (receiver === expected)
+ #
+ # receiver.should_not =~ regexp
+ # => Passes unless (receiver =~ regexp)
+ #
+ # See Spec::Matchers for more information about matchers
+ def should_not(matcher=nil, message=nil, &block)
+ Spec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb b/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb
new file mode 100644
index 000000000..5e01f99df
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb
@@ -0,0 +1,45 @@
+module Spec
+ module Expectations
+ class << self
+ attr_accessor :differ
+
+ # raises a Spec::Expectations::ExpectationNotMetError with message
+ #
+ # When a differ has been assigned and fail_with is passed
+ # <code>expected</code> and <code>target</code>, passes them
+ # to the differ to append a diff message to the failure message.
+ def fail_with(message, expected=nil, target=nil) # :nodoc:
+ if message.nil?
+ raise ArgumentError, "Failure message is nil. Does your matcher define the " +
+ "appropriate failure_message_for_* method to return a string?"
+ end
+ if (Array === message) & (message.length == 3)
+ ::Spec.warn(<<-NOTICE
+
+*****************************************************************
+DEPRECATION WARNING: you are using deprecated behaviour that will
+be removed from a future version of RSpec.
+
+* Support for matchers that return arrays from failure message
+methods is deprecated.
+* Instead, the matcher should return a string, and expose methods
+for the expected() and actual() values.
+*****************************************************************
+NOTICE
+ )
+ message, expected, target = message[0], message[1], message[2]
+ end
+ unless (differ.nil? || expected.nil? || target.nil?)
+ if expected.is_a?(String)
+ message << "\n\n Diff:" << self.differ.diff_as_string(target.to_s, expected)
+ elsif expected.is_a?(Hash) && target.is_a?(Hash)
+ message << "\n\n Diff:" << self.differ.diff_as_hash(target, expected)
+ elsif !target.is_a?(Proc)
+ message << "\n\n Diff:" << self.differ.diff_as_object(target, expected)
+ end
+ end
+ Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/vendor/plugins/rspec/lib/spec/matchers/be_instance_of.rb b/vendor/plugins/rspec/lib/spec/matchers/be_instance_of.rb
new file mode 100644
index 000000000..ffc238405
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/be_instance_of.rb
@@ -0,0 +1,26 @@
+module Spec
+ module Matchers
+ # :call-seq:
+ # should be_instance_of(expected)
+ # should be_an_instance_of(expected)
+ # should_not be_instance_of(expected)
+ # should_not be_an_instance_of(expected)
+ #
+ # Passes if actual.instance_of?(expected)
+ #
+ # == Examples
+ #
+ # 5.should be_instance_of(Fixnum)
+ # 5.should_not be_instance_of(Numeric)
+ # 5.should_not be_instance_of(Float)
+ def be_an_instance_of(expected)
+ Matcher.new :be_an_instance_of, expected do |_expected_|
+ match do |actual|
+ actual.instance_of?(_expected_)
+ end
+ end
+ end
+
+ alias_method :be_instance_of, :be_an_instance_of
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/matchers/be_kind_of.rb b/vendor/plugins/rspec/lib/spec/matchers/be_kind_of.rb
new file mode 100644
index 000000000..6a1fddc13
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/be_kind_of.rb
@@ -0,0 +1,26 @@
+module Spec
+ module Matchers
+ # :call-seq:
+ # should be_kind_of(expected)
+ # should be_a_kind_of(expected)
+ # should_not be_kind_of(expected)
+ # should_not be_a_kind_of(expected)
+ #
+ # Passes if actual.kind_of?(expected)
+ #
+ # == Examples
+ #
+ # 5.should be_kind_of(Fixnum)
+ # 5.should be_kind_of(Numeric)
+ # 5.should_not be_kind_of(Float)
+ def be_a_kind_of(expected)
+ Matcher.new :be_a_kind_of, expected do |_expected_|
+ match do |actual|
+ actual.kind_of?(_expected_)
+ end
+ end
+ end
+
+ alias_method :be_kind_of, :be_a_kind_of
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/matchers/compatibility.rb b/vendor/plugins/rspec/lib/spec/matchers/compatibility.rb
new file mode 100644
index 000000000..3b3ddb9b6
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/compatibility.rb
@@ -0,0 +1,14 @@
+Spec::Matchers.constants.each do |c|
+ if Class === (klass = Spec::Matchers.const_get(c))
+ if klass.public_instance_methods.any? {|m| ['failure_message_for_should',:failure_message_for_should].include?(m)}
+ klass.class_eval do
+ alias_method :failure_message, :failure_message_for_should
+ end
+ end
+ if klass.public_instance_methods.any? {|m| ['failure_message_for_should_not',:failure_message_for_should_not].include?(m)}
+ klass.class_eval do
+ alias_method :negative_failure_message, :failure_message_for_should_not
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/matchers/dsl.rb b/vendor/plugins/rspec/lib/spec/matchers/dsl.rb
new file mode 100644
index 000000000..73f363457
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/dsl.rb
@@ -0,0 +1,20 @@
+module Spec
+ module Matchers
+ module DSL
+ # See Spec::Matchers
+ def define(name, &declarations)
+ define_method name do |*expected|
+ Spec::Matchers::Matcher.new name, *expected, &declarations
+ end
+ end
+
+ # Deprecated - use define
+ def create(name, &declarations)
+ Spec.deprecate("Spec::Matchers.create","Spec::Matchers.define")
+ define(name, &declarations)
+ end
+ end
+ end
+end
+
+Spec::Matchers.extend Spec::Matchers::DSL
diff --git a/vendor/plugins/rspec/lib/spec/matchers/errors.rb b/vendor/plugins/rspec/lib/spec/matchers/errors.rb
new file mode 100644
index 000000000..49c267797
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/errors.rb
@@ -0,0 +1,5 @@
+module Spec
+ module Matchers
+ class MatcherError < StandardError; end
+ end
+end \ No newline at end of file
diff --git a/vendor/plugins/rspec/lib/spec/matchers/extensions/instance_exec.rb b/vendor/plugins/rspec/lib/spec/matchers/extensions/instance_exec.rb
new file mode 100644
index 000000000..ca7e14ead
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/extensions/instance_exec.rb
@@ -0,0 +1,31 @@
+module Spec
+ module Matchers
+ module InstanceExec
+ unless respond_to?(:instance_exec)
+ # based on Bounded Spec InstanceExec (Mauricio Fernandez)
+ # http://eigenclass.org/hiki/bounded+space+instance_exec
+ # - uses singleton_class of matcher instead of global
+ # InstanceExecHelper module
+ # - this keeps it scoped to this class only, which is the
+ # only place we need it
+ # - only necessary for ruby 1.8.6
+ def instance_exec(*args, &block)
+ singleton_class = (class << self; self; end)
+ begin
+ orig_critical, Thread.critical = Thread.critical, true
+ n = 0
+ n += 1 while respond_to?(method_name="__instance_exec#{n}")
+ singleton_class.module_eval{ define_method(:__instance_exec, &block) }
+ ensure
+ Thread.critical = orig_critical
+ end
+ begin
+ return send(:__instance_exec, *args)
+ ensure
+ singleton_class.module_eval{ remove_method(:__instance_exec) } rescue nil
+ end
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/vendor/plugins/rspec/lib/spec/matchers/generated_descriptions.rb b/vendor/plugins/rspec/lib/spec/matchers/generated_descriptions.rb
new file mode 100644
index 000000000..2340f57d8
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/generated_descriptions.rb
@@ -0,0 +1,36 @@
+module Spec
+ module Matchers
+ class << self
+ attr_accessor :last_matcher, :last_should # :nodoc:
+ end
+
+ def self.clear_generated_description
+ self.last_matcher = nil
+ self.last_should = nil
+ end
+
+ def self.generated_description
+ return nil if last_should.nil?
+ "#{last_should.to_s.gsub('_',' ')} #{last_description}"
+ end
+
+ private
+
+ def self.last_description
+ last_matcher.respond_to?(:description) ? last_matcher.description : <<-MESSAGE
+When you call a matcher in an example without a String, like this:
+
+specify { object.should matcher }
+
+or this:
+
+it { should matcher }
+
+RSpec expects the matcher to have a #description method. You should either
+add a String to the example this matcher is being used in, or give it a
+description method. Then you won't have to suffer this lengthy warning again.
+MESSAGE
+ end
+ end
+end
+
diff --git a/vendor/plugins/rspec/lib/spec/matchers/match_array.rb b/vendor/plugins/rspec/lib/spec/matchers/match_array.rb
new file mode 100644
index 000000000..51b4f3929
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/match_array.rb
@@ -0,0 +1,71 @@
+module Spec
+ module Matchers
+
+ class MatchArray #:nodoc:
+ include Spec::Matchers::Pretty
+
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def matches?(actual)
+ @actual = actual
+ @extra_items = difference_between_arrays(@actual, @expected)
+ @missing_items = difference_between_arrays(@expected, @actual)
+ @extra_items.empty? & @missing_items.empty?
+ end
+
+ def failure_message_for_should
+ message = "expected collection contained: #{safe_sort(@expected).inspect}\n"
+ message += "actual collection contained: #{safe_sort(@actual).inspect}\n"
+ message += "the missing elements were: #{safe_sort(@missing_items).inspect}\n" unless @missing_items.empty?
+ message += "the extra elements were: #{safe_sort(@extra_items).inspect}\n" unless @extra_items.empty?
+ message
+ end
+
+ def failure_message_for_should_not
+ "Matcher does not support should_not"
+ end
+
+ def description
+ "contain exactly #{_pretty_print(@expected)}"
+ end
+
+ private
+
+ def safe_sort(array)
+ array.all?{|item| item.respond_to?(:<=>)} ? array.sort : array
+ end
+
+ def difference_between_arrays(array_1, array_2)
+ difference = array_1.dup
+ array_2.each do |element|
+ if index = difference.index(element)
+ difference.delete_at(index)
+ end
+ end
+ difference
+ end
+
+
+ end
+
+ # :call-seq:
+ # should =~ expected
+ #
+ # Passes if actual contains all of the expected regardless of order.
+ # This works for collections. Pass in multiple args and it will only
+ # pass if all args are found in collection.
+ #
+ # NOTE: there is no should_not version of array.should =~ other_array
+ #
+ # == Examples
+ #
+ # [1,2,3].should =~ [1,2,3] # => would pass
+ # [1,2,3].should =~ [2,3,1] # => would pass
+ # [1,2,3,4].should =~ [1,2,3] # => would fail
+ # [1,2,2,3].should =~ [1,2,3] # => would fail
+ # [1,2,3].should =~ [1,2,3,4] # => would fail
+ OperatorMatcher.register(Array, '=~', Spec::Matchers::MatchArray)
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/matchers/matcher.rb b/vendor/plugins/rspec/lib/spec/matchers/matcher.rb
new file mode 100644
index 000000000..165ddffb5
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/matcher.rb
@@ -0,0 +1,87 @@
+module Spec
+ module Matchers
+ class Matcher
+ include Spec::Matchers::InstanceExec
+ include Spec::Matchers::Pretty
+ include Spec::Matchers
+
+ attr_reader :expected, :actual
+
+ def initialize(name, *expected, &declarations)
+ @name = name
+ @expected = expected
+ @actual = nil
+ @diffable = false
+ @messages = {
+ :description => lambda {"#{name_to_sentence}#{expected_to_sentence}"},
+ :failure_message_for_should => lambda {|actual| "expected #{actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"},
+ :failure_message_for_should_not => lambda {|actual| "expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"}
+ }
+ making_declared_methods_public do
+ instance_exec(*@expected, &declarations)
+ end
+ end
+
+ def matches?(actual)
+ instance_exec(@actual = actual, &@match_block)
+ end
+
+ def description(&block)
+ cache_or_call_cached(:description, &block)
+ end
+
+ def failure_message_for_should(&block)
+ cache_or_call_cached(:failure_message_for_should, actual, &block)
+ end
+
+ def failure_message_for_should_not(&block)
+ cache_or_call_cached(:failure_message_for_should_not, actual, &block)
+ end
+
+ def match(&block)
+ @match_block = block
+ end
+
+ def diffable?
+ @diffable
+ end
+
+ def diffable
+ @diffable = true
+ end
+
+ private
+
+ def making_declared_methods_public # :nodoc:
+ # Our home-grown instance_exec in ruby 1.8.6 results in any methods
+ # declared in the block eval'd by instance_exec in the block to which we
+ # are yielding here are scoped private. This is NOT the case for Ruby
+ # 1.8.7 or 1.9.
+ #
+ # Also, due some crazy scoping that I don't understand, these methods
+ # are actually available in the specs (something about the matcher being
+ # defined in the scope of Spec::Matchers or within an example), so not
+ # doing the following will not cause specs to fail, but they *will*
+ # cause features to fail and that will make users unhappy. So don't.
+ orig_private_methods = private_methods
+ yield
+ st = (class << self; self; end)
+ (private_methods - orig_private_methods).each {|m| st.__send__ :public, m}
+ end
+
+ def cache_or_call_cached(key, actual=nil, &block)
+ block ? @messages[key] = block :
+ actual.nil? ? @messages[key].call : @messages[key].call(actual)
+ end
+
+ def name_to_sentence
+ split_words(@name)
+ end
+
+ def expected_to_sentence
+ to_sentence(@expected)
+ end
+
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb b/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb
new file mode 100644
index 000000000..ae7f39795
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb
@@ -0,0 +1,9 @@
+module Spec
+ module Matchers
+ def method_missing(sym, *args, &block) # :nodoc:
+ return Matchers::Be.new(sym, *args) if sym.to_s =~ /^be_/
+ return Matchers::Has.new(sym, *args) if sym.to_s =~ /^have_/
+ super
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/matchers/pretty.rb b/vendor/plugins/rspec/lib/spec/matchers/pretty.rb
new file mode 100644
index 000000000..152058373
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/pretty.rb
@@ -0,0 +1,37 @@
+module Spec
+ module Matchers
+ module Pretty
+ def split_words(sym)
+ sym.to_s.gsub(/_/,' ')
+ end
+
+ def to_sentence(words)
+ words = words.map{|w| w.inspect}
+ case words.length
+ when 0
+ ""
+ when 1
+ " #{words[0]}"
+ when 2
+ " #{words[0]} and #{words[1]}"
+ else
+ " #{words[0...-1].join(', ')}, and #{words[-1]}"
+ end
+ end
+
+ def _pretty_print(array)
+ result = ""
+ array.each_with_index do |item, index|
+ if index < (array.length - 2)
+ result << "#{item.inspect}, "
+ elsif index < (array.length - 1)
+ result << "#{item.inspect} and "
+ else
+ result << "#{item.inspect}"
+ end
+ end
+ result
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/vendor/plugins/rspec/lib/spec/matchers/wrap_expectation.rb b/vendor/plugins/rspec/lib/spec/matchers/wrap_expectation.rb
new file mode 100644
index 000000000..95162cae1
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/matchers/wrap_expectation.rb
@@ -0,0 +1,55 @@
+module Spec
+ module Matchers
+ # wraps an expectation in a block that will return true if the
+ # expectation passes and false if it fails (without bubbling up
+ # the failure).
+ #
+ # This is intended to be used in the context of a simple matcher,
+ # and is especially useful for wrapping multiple expectations or
+ # one or more assertions from test/unit extensions when running
+ # with test/unit.
+ #
+ # == Examples
+ #
+ # def eat_cheese(cheese)
+ # simple_matcher do |mouse, matcher|
+ # matcher.failure_message = "expected #{mouse} to eat cheese"
+ # wrap_expectation do |matcher|
+ # assert_eats_cheese(mouse)
+ # end
+ # end
+ # end
+ #
+ # describe Mouse do
+ # it "eats cheese" do
+ # Mouse.new.should eat_cheese
+ # end
+ # end
+ #
+ # You might be wondering "why would I do this if I could just say"
+ # assert_eats_cheese?", a fair question, indeed. You might prefer
+ # to replace the word assert with something more aligned with the
+ # rest of your code examples. You are using rspec, after all.
+ #
+ # The other benefit you get is that you can use the negative version
+ # of the matcher:
+ #
+ # describe Cat do
+ # it "does not eat cheese" do
+ # Cat.new.should_not eat_cheese
+ # end
+ # end
+ #
+ # So in the event there is no assert_does_not_eat_cheese available,
+ # you're all set!
+ def wrap_expectation(matcher, &block)
+ begin
+ block.call(matcher)
+ return true
+ rescue Exception => e
+ matcher.failure_message = e.message
+ return false
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/mocks/argument_matchers.rb b/vendor/plugins/rspec/lib/spec/mocks/argument_matchers.rb
new file mode 100644
index 000000000..f56551f21
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/mocks/argument_matchers.rb
@@ -0,0 +1,237 @@
+module Spec
+ module Mocks
+
+ # ArgumentMatchers are messages that you can include in message
+ # expectations to match arguments against a broader check than simple
+ # equality.
+ #
+ # With the exception of any_args() and no_args(), the matchers
+ # are all positional - they match against the arg in the given position.
+ module ArgumentMatchers
+
+ class AnyArgsMatcher
+ def description
+ "any args"
+ end
+ end
+
+ class NoArgsMatcher
+ def description
+ "no args"
+ end
+ end
+
+ class AnyArgMatcher
+ def initialize(ignore)
+ end
+
+ def ==(other)
+ true
+ end
+
+ def description
+ "anything"
+ end
+ end
+
+ class RegexpMatcher
+ def initialize(regexp)
+ @regexp = regexp
+ end
+
+ def ==(value)
+ return value =~ @regexp unless value.is_a?(Regexp)
+ value == @regexp
+ end
+ end
+
+ class BooleanMatcher
+ def initialize(ignore)
+ end
+
+ def ==(value)
+ TrueClass === value || FalseClass === value
+ end
+ end
+
+ class HashIncludingMatcher
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def ==(actual)
+ @expected.each do | key, value |
+ return false unless actual.has_key?(key) && value == actual[key]
+ end
+ true
+ rescue NoMethodError => ex
+ return false
+ end
+
+ def description
+ "hash_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
+ end
+ end
+
+ class HashNotIncludingMatcher
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def ==(actual)
+ @expected.each do | key, value |
+ return false if actual.has_key?(key) && value == actual[key]
+ end
+ true
+ rescue NoMethodError => ex
+ return false
+ end
+
+ def description
+ "hash_not_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
+ end
+ end
+
+ class DuckTypeMatcher
+ def initialize(*methods_to_respond_to)
+ @methods_to_respond_to = methods_to_respond_to
+ end
+
+ def ==(value)
+ @methods_to_respond_to.all? { |sym| value.respond_to?(sym) }
+ end
+ end
+
+ class MatcherMatcher
+ def initialize(matcher)
+ @matcher = matcher
+ end
+
+ def ==(value)
+ @matcher.matches?(value)
+ end
+ end
+
+ class EqualityProxy
+ def initialize(given)
+ @given = given
+ end
+
+ def ==(expected)
+ @given == expected
+ end
+ end
+
+ class InstanceOf
+ def initialize(klass)
+ @klass = klass
+ end
+
+ def ==(actual)
+ actual.instance_of?(@klass)
+ end
+ end
+
+ class KindOf
+ def initialize(klass)
+ @klass = klass
+ end
+
+ def ==(actual)
+ actual.kind_of?(@klass)
+ end
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(no_args())
+ #
+ # Passes if no arguments are passed along with the message
+ def no_args
+ NoArgsMatcher.new
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(any_args())
+ #
+ # Passes if object receives :message with any args at all. This is
+ # really a more explicit variation of object.should_receive(:message)
+ def any_args
+ AnyArgsMatcher.new
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(anything())
+ #
+ # Passes as long as there is an argument.
+ def anything
+ AnyArgMatcher.new(nil)
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(duck_type(:hello))
+ # object.should_receive(:message).with(duck_type(:hello, :goodbye))
+ #
+ # Passes if the argument responds to the specified messages.
+ #
+ # == Examples
+ #
+ # array = []
+ # display = mock('display')
+ # display.should_receive(:present_names).with(duck_type(:length, :each))
+ # => passes
+ def duck_type(*args)
+ DuckTypeMatcher.new(*args)
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(boolean())
+ #
+ # Passes if the argument is boolean.
+ def boolean
+ BooleanMatcher.new(nil)
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(hash_including(:key => val))
+ # object.should_receive(:message).with(hash_including(:key))
+ # object.should_receive(:message).with(hash_including(:key, :key2 => val2))
+ # Passes if the argument is a hash that includes the specified key(s) or key/value
+ # pairs. If the hash includes other keys, it will still pass.
+ def hash_including(*args)
+ HashIncludingMatcher.new(anythingize_lonely_keys(*args))
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(hash_not_including(:key => val))
+ # object.should_receive(:message).with(hash_not_including(:key))
+ # object.should_receive(:message).with(hash_not_including(:key, :key2 => :val2))
+ #
+ # Passes if the argument is a hash that doesn't include the specified key(s) or key/value
+ def hash_not_including(*args)
+ HashNotIncludingMatcher.new(anythingize_lonely_keys(*args))
+ end
+
+ # Passes if arg.instance_of?(klass)
+ def instance_of(klass)
+ InstanceOf.new(klass)
+ end
+
+ alias_method :an_instance_of, :instance_of
+
+ # Passes if arg.kind_of?(klass)
+ def kind_of(klass)
+ KindOf.new(klass)
+ end
+
+ alias_method :a_kind_of, :kind_of
+
+ private
+
+ def anythingize_lonely_keys(*args)
+ hash = args.last.class == Hash ? args.delete_at(-1) : {}
+ args.each { | arg | hash[arg] = anything }
+ hash
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/mocks/example_methods.rb b/vendor/plugins/rspec/lib/spec/mocks/example_methods.rb
new file mode 100644
index 000000000..f6c68ab6a
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/mocks/example_methods.rb
@@ -0,0 +1,69 @@
+module Spec
+ module Mocks
+ module ExampleMethods
+ include Spec::Mocks::ArgumentMatchers
+
+ # Shortcut for creating an instance of Spec::Mocks::Mock.
+ #
+ # +name+ is used for failure reporting, so you should use the
+ # role that the double is playing in the example.
+ #
+ # +stubs_and_options+ lets you assign options and stub values
+ # at the same time. The only option available is :null_object.
+ # Anything else is treated as a stub value.
+ #
+ # == Examples
+ #
+ # thing = double("thing", :a => "A")
+ # thing.a == "A" => true
+ #
+ # person = double("thing", :name => "Joe", :email => "joe@domain.com")
+ # person.name => "Joe"
+ # person.email => "joe@domain.com"
+ def double(*args)
+ __declare_double('Double', *args)
+ end
+
+ # Alias for double
+ def mock(*args)
+ __declare_double('Mock', *args)
+ end
+
+ # Alias for double
+ def stub(*args)
+ __declare_double('Stub', *args)
+ end
+
+ def __declare_double(declared_as, *args) # :nodoc:
+ args << {} unless Hash === args.last
+ args.last[:__declared_as] = declared_as
+ Spec::Mocks::Mock.new(*args)
+ end
+
+ # DEPRECATED - use double('name').as_null_object instead
+ #
+ # Shortcut for creating a mock object that will return itself in response
+ # to any message it receives that it hasn't been explicitly instructed
+ # to respond to.
+ def stub_everything(name = 'stub')
+ Spec.warn(<<-WARNING)
+
+DEPRECATION: stub_everything('#{name}') is deprecated and will be removed
+from a future version of rspec. Please use double('#{name}').as_null_object
+(or stub('#{name}').as_null_object or mock('#{name}').as_null_object instead.
+
+WARNING
+ mock(name, :null_object => true)
+ end
+
+ # Disables warning messages about expectations being set on nil.
+ #
+ # By default warning messages are issued when expectations are set on nil. This is to
+ # prevent false-positives and to catch potential bugs early on.
+ def allow_message_expectations_on_nil
+ Proxy.allow_message_expectations_on_nil
+ end
+
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/ruby.rb b/vendor/plugins/rspec/lib/spec/ruby.rb
new file mode 100644
index 000000000..863877c7f
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/ruby.rb
@@ -0,0 +1,9 @@
+module Spec
+ module Ruby
+ class << self
+ def version
+ RUBY_VERSION
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/runner/configuration.rb b/vendor/plugins/rspec/lib/spec/runner/configuration.rb
new file mode 100644
index 000000000..d211565df
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/runner/configuration.rb
@@ -0,0 +1,194 @@
+module Spec
+ module Runner
+ class Configuration
+ include Spec::Example::ArgsAndOptions
+
+ # Chooses what mock framework to use. Example:
+ #
+ # Spec::Runner.configure do |config|
+ # config.mock_with :rspec, :mocha, :flexmock, or :rr
+ # end
+ #
+ # To use any other mock framework, you'll have to provide your own
+ # adapter. This is simply a module that responds to the following
+ # methods:
+ #
+ # setup_mocks_for_rspec
+ # verify_mocks_for_rspec
+ # teardown_mocks_for_rspec.
+ #
+ # These are your hooks into the lifecycle of a given example. RSpec will
+ # call setup_mocks_for_rspec before running anything else in each
+ # Example. After executing the #after methods, RSpec will then call
+ # verify_mocks_for_rspec and teardown_mocks_for_rspec (this is
+ # guaranteed to run even if there are failures in
+ # verify_mocks_for_rspec).
+ #
+ # Once you've defined this module, you can pass that to mock_with:
+ #
+ # Spec::Runner.configure do |config|
+ # config.mock_with MyMockFrameworkAdapter
+ # end
+ #
+ def mock_with(mock_framework)
+ @mock_framework = case mock_framework
+ when Symbol
+ mock_framework_path(mock_framework.to_s)
+ else
+ mock_framework
+ end
+ end
+
+ def mock_framework # :nodoc:
+ @mock_framework ||= mock_framework_path("rspec")
+ end
+
+ # :call-seq:
+ # include(Some::Helpers)
+ # include(Some::Helpers, More::Helpers)
+ # include(My::Helpers, :type => :key)
+ #
+ # Declares modules to be included in multiple example groups
+ # (<tt>describe</tt> blocks). With no <tt>:type</tt>, the modules listed
+ # will be included in all example groups.
+ #
+ # Use <tt>:type</tt> to restrict
+ # the inclusion to a subset of example groups. The value assigned to
+ # <tt>:type</tt> should be a key that maps to a class that is either a
+ # subclass of Spec::Example::ExampleGroup or extends
+ # Spec::Example::ExampleGroupMethods and includes
+ # Spec::Example::ExampleMethods.
+ #
+ # For example, the rspec-rails gem/plugin extends Test::Unit::TestCase
+ # with Spec::Example::ExampleGroupMethods and includes
+ # Spec::Example::ExampleMethods in it. So if you have a module of helper
+ # methods for controller examples, you could do this:
+ #
+ # config.include(ControllerExampleHelpers, :type => :controller)
+ #
+ # Only example groups that have that type will get the modules included:
+ #
+ # describe Account, :type => :model do
+ # # Will *not* include ControllerExampleHelpers
+ # end
+ #
+ # describe AccountsController, :type => :controller do
+ # # *Will* include ControllerExampleHelpers
+ # end
+ #
+ def include(*modules_and_options)
+ include_or_extend(:include, *modules_and_options)
+ end
+
+ # :call-seq:
+ # extend(Some::Helpers)
+ # extend(Some::Helpers, More::Helpers)
+ # extend(My::Helpers, :type => :key)
+ #
+ # Works just like #include, but extends the example groups
+ # with the modules rather than including them.
+ def extend(*modules_and_options)
+ include_or_extend(:extend, *modules_and_options)
+ end
+
+ # Appends a global <tt>before</tt> block to all example groups.
+ # <tt>scope</tt> can be any of <tt>:each</tt> (default), <tt>:all</tt>, or
+ # <tt>:suite</tt>. When <tt>:each</tt>, the block is executed before each
+ # example. When <tt>:all</tt>, the block is executed once per example
+ # group, before any of its examples are run. When <tt>:suite</tt> the
+ # block is run once before the entire suite is run.
+ def append_before(scope = :each, options={}, &proc)
+ add_callback(:append_before, scope, options, &proc)
+ end
+ alias_method :before, :append_before
+
+ # Prepends a global <tt>before</tt> block to all example groups.
+ #
+ # See <tt>append_before</tt> for scoping semantics.
+ def prepend_before(scope = :each, options={}, &proc)
+ add_callback(:prepend_before, scope, options, &proc)
+ end
+
+ # Prepends a global <tt>after</tt> block to all example groups.
+ #
+ # See <tt>append_before</tt> for scoping semantics.
+ def prepend_after(scope = :each, options={}, &proc)
+ add_callback(:prepend_after, scope, options, &proc)
+ end
+ alias_method :after, :prepend_after
+
+ # Appends a global <tt>after</tt> block to all example groups.
+ #
+ # See <tt>append_before</tt> for scoping semantics.
+ def append_after(scope = :each, options={}, &proc)
+ add_callback(:append_after, scope, options, &proc)
+ end
+
+ # DEPRECATED - use Spec::Matchers::DSL instead
+ #
+ # Defines global predicate matchers. Example:
+ #
+ # config.predicate_matchers[:swim] = :can_swim?
+ #
+ # This makes it possible to say:
+ #
+ # person.should swim # passes if person.can_swim? returns true
+ #
+ def predicate_matchers
+ @predicate_matchers ||= Spec::HashWithDeprecationNotice.new("predicate_matchers", "the new Matcher DSL")
+ end
+
+ # Adds patterns to the list of patterns ignored in the backtrace when a
+ # failure is output by rspec. Example:
+ #
+ # config.ignore_backtrace_patterns /spork/, /shoulda/, "/some/weird/path/"
+ #
+ # When quiet backtraces are turned on (default), this will exclude any
+ # lines that match any of the Regexps and Strings passed.
+ #
+ def ignore_backtrace_patterns(*patterns)
+ @ignored_backtrace_patterns ||= []
+ @ignored_backtrace_patterns += patterns
+ end
+
+ def ignored_backtrace_patterns # :nodoc:
+ @ignored_backtrace_patterns ||= []
+ end
+
+ private
+
+ def include_or_extend(action, *args)
+ modules, options = args_and_options(*args)
+ [get_type_from_options(options)].flatten.each do |required_example_group|
+ required_example_group = required_example_group.to_sym if required_example_group
+ modules.each do |mod|
+ Spec::Example::ExampleGroupFactory[required_example_group].__send__(action, mod)
+ end
+ end
+ end
+
+ def add_callback(sym, *args, &proc)
+ scope, options = scope_and_options(*args)
+ example_group = Spec::Example::ExampleGroupFactory[get_type_from_options(options)]
+ example_group.__send__(sym, scope, &proc)
+ end
+
+ def get_type_from_options(options)
+ options[:type] || options[:behaviour_type]
+ end
+
+ def mock_framework_path(framework_name)
+ "spec/adapters/mock_frameworks/#{framework_name}"
+ end
+
+ def scope_and_options(*args) # :nodoc:
+ args, options = args_and_options(*args)
+ return scope_from(*args), options
+ end
+
+ def scope_from(*args) # :nodoc:
+ args[0] || :each
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/runner/differs/default.rb b/vendor/plugins/rspec/lib/spec/runner/differs/default.rb
new file mode 100644
index 000000000..7f0a7e648
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/runner/differs/default.rb
@@ -0,0 +1,93 @@
+require 'spec/runner/differs/load-diff-lcs'
+require 'pp'
+
+module Spec
+ module Expectations
+ module Differs
+ unless defined?(Default)
+ class Default
+ def initialize(options)
+ @options = options
+ end
+
+ # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
+ def diff_as_string(data_new, data_old)
+ data_old = data_old.split(/\n/).map! { |e| e.chomp }
+ data_new = data_new.split(/\n/).map! { |e| e.chomp }
+ output = ""
+ diffs = Diff::LCS.diff(data_old, data_new)
+ return output if diffs.empty?
+ oldhunk = hunk = nil
+ file_length_difference = 0
+ diffs.each do |piece|
+ begin
+ hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
+ file_length_difference)
+ file_length_difference = hunk.file_length_difference
+ next unless oldhunk
+ # Hunks may overlap, which is why we need to be careful when our
+ # diff includes lines of context. Otherwise, we might print
+ # redundant lines.
+ if (context_lines > 0) and hunk.overlaps?(oldhunk)
+ hunk.unshift(oldhunk)
+ else
+ output << oldhunk.diff(format)
+ end
+ ensure
+ oldhunk = hunk
+ output << "\n"
+ end
+ end
+ #Handle the last remaining hunk
+ output << oldhunk.diff(format) << "\n"
+ end
+
+ def diff_as_object(target,expected)
+ diff_as_string(PP.pp(target,""), PP.pp(expected,""))
+ end
+
+ def diff_as_hash(target, expected)
+ contains_hash = false
+ contains_array = false
+
+ extra_expected_keys = expected.keys - target.keys
+ extra_target_keys = target.keys - expected.keys
+
+ o = "\n"
+
+ o << "Expected hash contains keys that target hash does not: " << extra_expected_keys.inspect << "\n" if !extra_expected_keys.empty?
+ o << "Target hash contains keys that expected hash does not: " << extra_target_keys.inspect << "\n" if !extra_target_keys.empty?
+
+ expected.delete_if do |key, value|
+ contains_hash = true if value.is_a?(Hash)
+ contains_array = true if value.is_a?(Array)
+ target[key] == value
+ end
+
+ expected.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |key|
+ o << "Expected the key #{key.inspect} to be #{expected[key].inspect}, but was #{target[key].inspect}\n"
+ end
+
+ o << "\n"
+
+ if contains_hash || contains_array
+ o << diff_as_object(target, expected)
+ else
+ o
+ end
+ end
+
+ protected
+ def format
+ @options.diff_format
+ end
+
+ def context_lines
+ @options.context_lines
+ end
+ end
+
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/runner/differs/load-diff-lcs.rb b/vendor/plugins/rspec/lib/spec/runner/differs/load-diff-lcs.rb
new file mode 100644
index 000000000..f708bc9b4
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/runner/differs/load-diff-lcs.rb
@@ -0,0 +1,12 @@
+begin
+ require 'diff/lcs'
+rescue LoadError
+ begin
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
+ require 'diff/lcs'
+ rescue LoadError
+ raise "You must gem install diff-lcs to use diffing"
+ end
+end
+
+require 'diff/lcs/hunk'
diff --git a/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb b/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb
new file mode 100644
index 000000000..4e23cdf22
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb
@@ -0,0 +1,9 @@
+module Kernel
+ unless respond_to?(:debugger)
+ # Start a debugging session if ruby-debug is loaded with the -u/--debugger option
+ def debugger(steps=1)
+ # If not then just comment and proceed
+ $stderr.puts "debugger statement ignored, use -u or --debugger option on rspec to enable debugging"
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/runner/formatter/no_op_method_missing.rb b/vendor/plugins/rspec/lib/spec/runner/formatter/no_op_method_missing.rb
new file mode 100644
index 000000000..350e29f73
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/runner/formatter/no_op_method_missing.rb
@@ -0,0 +1,21 @@
+module Spec
+ module Runner
+ module Formatter
+ module NOOPMethodMissing
+ def respond_to?(message, include_private = false)
+ if include_private
+ true
+ else
+ !private_methods.any? {|m| [message.to_s, message.to_sym].include?(m)}
+ end
+ end
+
+ private
+
+ def method_missing(sym, *args)
+ # a no-op
+ end
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/runner/formatter/silent_formatter.rb b/vendor/plugins/rspec/lib/spec/runner/formatter/silent_formatter.rb
new file mode 100644
index 000000000..43cce33bb
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/runner/formatter/silent_formatter.rb
@@ -0,0 +1,10 @@
+require 'spec/runner/formatter/base_formatter'
+
+module Spec
+ module Runner
+ module Formatter
+ class SilentFormatter < BaseFormatter
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/runner/line_number_query.rb b/vendor/plugins/rspec/lib/spec/runner/line_number_query.rb
new file mode 100644
index 000000000..0a907d3fe
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/runner/line_number_query.rb
@@ -0,0 +1,78 @@
+module Spec
+ module Runner
+ # Parses a spec file and finds the nearest example for a given line number.
+ class LineNumberQuery
+ attr_reader :best_match
+
+ def initialize(run_options)
+ @best_match = {}
+ @run_options = run_options
+ end
+
+ def spec_name_for(file, line_number)
+ best_match.clear
+ file = File.expand_path(file)
+ determine_best_match(file, line_number)
+ if best_match[:example_group]
+ if best_match[:example]
+ "#{best_match[:example_group].description} #{best_match[:example].description}"
+ else
+ best_match[:example_group].description
+ end
+ else
+ nil
+ end
+ end
+
+ def example_line_for(file, line_number)
+ determine_best_match(file, line_number)
+ best_match[:line]
+ end
+
+ protected
+
+ def determine_best_match(file, line_number)
+ best_match.clear
+ file = File.expand_path(file)
+ @run_options.example_groups.each do |example_group|
+ next unless example_group.location
+ consider_example_group_for_best_match(example_group, file, line_number)
+
+ example_group.examples.each do |example|
+ consider_example_for_best_match(example, example_group, file, line_number)
+ end
+ end
+ end
+
+ def consider_example_group_for_best_match(example_group, file, line_number)
+ example_group_file, example_group_line = parse_location(example_group.location)
+ if is_best_match?(file, line_number, example_group_file, example_group_line)
+ best_match.clear
+ best_match[:example_group] = example_group
+ best_match[:line] = example_group_line
+ end
+ end
+
+ def consider_example_for_best_match(example, example_group, file, line_number)
+ example_file, example_line = parse_location(example.location)
+ if is_best_match?(file, line_number, example_file, example_line)
+ best_match.clear
+ best_match[:example_group] = example_group
+ best_match[:example] = example
+ best_match[:line] = example_line
+ end
+ end
+
+ def is_best_match?(file, line_number, example_file, example_line)
+ file == File.expand_path(example_file) &&
+ example_line <= line_number &&
+ example_line > best_match[:line].to_i
+ end
+
+ def parse_location(location)
+ location =~ /(.*)\:(\d*)(\:|$)/
+ return $1, Integer($2)
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/rspec/lib/spec/stubs/cucumber.rb b/vendor/plugins/rspec/lib/spec/stubs/cucumber.rb
new file mode 100644
index 000000000..b801ef442
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/stubs/cucumber.rb
@@ -0,0 +1,5 @@
+# This plugs RSpec's mocking/stubbing framework into cucumber
+require 'spec/mocks'
+Before {$rspec_stubs ||= Spec::Mocks::Space.new}
+After {$rspec_stubs.reset_all}
+World(Spec::Mocks::ExampleMethods)
diff --git a/vendor/plugins/rspec/lib/spec/test/unit.rb b/vendor/plugins/rspec/lib/spec/test/unit.rb
new file mode 100644
index 000000000..fb4eb4932
--- /dev/null
+++ b/vendor/plugins/rspec/lib/spec/test/unit.rb
@@ -0,0 +1,10 @@
+require 'spec/interop/test'
+
+# Hack to stop active_support/dependencies from complaining about
+# 'spec/test/unit' not defining Spec::Test::Unit
+module Spec
+ module Test
+ module Unit
+ end
+ end
+end