diff options
author | Louise Crow <louise.crow@gmail.com> | 2011-02-24 15:10:14 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2011-02-24 15:10:14 +0000 |
commit | 08a64f9e3139851fd65c7ba6969ee590b4afea6a (patch) | |
tree | 20c77e796002dfa95b2af3ba00ebd2f691c02fc7 /vendor/gems/rspec-1.3.1/lib/spec/example | |
parent | 3757bb52c0aa86b779b00428d7ebe35b30cea1ee (diff) |
Adding rspec gem.
Diffstat (limited to 'vendor/gems/rspec-1.3.1/lib/spec/example')
16 files changed, 1154 insertions, 0 deletions
diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/args_and_options.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/args_and_options.rb new file mode 100644 index 000000000..b74fddd8e --- /dev/null +++ b/vendor/gems/rspec-1.3.1/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/gems/rspec-1.3.1/lib/spec/example/before_and_after_hooks.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/before_and_after_hooks.rb new file mode 100644 index 000000000..9f5039d1e --- /dev/null +++ b/vendor/gems/rspec-1.3.1/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/gems/rspec-1.3.1/lib/spec/example/errors.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/errors.rb new file mode 100644 index 000000000..157b669b0 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/errors.rb @@ -0,0 +1,25 @@ +module Spec + module Example + class ExamplePendingError < StandardError; end + + class NotYetImplementedError < ExamplePendingError + MESSAGE = "Not Yet Implemented" + def initialize + super(MESSAGE) + end + end + + class PendingExampleFixedError < StandardError; end + + class NoDescriptionError < ArgumentError + class << self + def message(kind, location) + "No description supplied for #{kind} declared on #{location}" + end + end + def initialize(kind, location) + super(self.class.message(kind, location)) + end + end + end +end diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/example_group.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/example_group.rb new file mode 100644 index 000000000..983be9a24 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/example_group.rb @@ -0,0 +1,10 @@ +module Spec + module Example + # Base class for customized example groups. Use this if you + # want to make a custom example group. + class ExampleGroup + extend Spec::Example::ExampleGroupMethods + include Spec::Example::ExampleMethods + end + end +end diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/example_group_factory.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/example_group_factory.rb new file mode 100644 index 000000000..1d662782a --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/example_group_factory.rb @@ -0,0 +1,82 @@ +module Spec + module Example + + class ExampleGroupFactory + module ClassMethods + include Spec::Example::ArgsAndOptions + + def reset + @example_group_types = nil + default(ExampleGroup) + end + + def example_group_creation_listeners + @example_group_creation_listeners ||= [] + end + + def register_example_group(klass) + example_group_creation_listeners.each do |listener| + listener.register_example_group(klass) + end + end + + 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) + superclass = determine_superclass(args.last) + superclass.describe(*args, &block) + end + + # Registers an example group class +klass+ with the symbol +type+. For + # example: + # + # Spec::Example::ExampleGroupFactory.register(:farm, FarmExampleGroup) + # + # With that you can append a hash with :type => :farm to the describe + # method and it will load an instance of FarmExampleGroup. + # + # describe Pig, :type => :farm do + # ... + # + # If you don't use the hash explicitly, <tt>describe</tt> will + # implicitly use an instance of FarmExampleGroup for any file loaded + # from the <tt>./spec/farm</tt> directory. + def register(key, example_group_class) + @example_group_types[key.to_sym] = example_group_class + end + + # Sets the default ExampleGroup class + def default(example_group_class) + Spec.__send__ :remove_const, :ExampleGroup if Spec.const_defined?(:ExampleGroup) + Spec.const_set(:ExampleGroup, example_group_class) + old = @example_group_types + @example_group_types = Hash.new(example_group_class) + @example_group_types.merge!(old) if old + end + + def [](key) + @example_group_types[key] + end + + protected + + def determine_superclass(opts) + if type = opts[:type] + self[type] + elsif opts[:location] =~ /spec(\\|\/)(#{@example_group_types.keys.sort_by{|k| k.to_s.length}.reverse.join('|')})/ + self[$2 == '' ? nil : $2.to_sym] + else + self[nil] + end + end + + end + extend ClassMethods + self.reset + end + end +end diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/example_group_hierarchy.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/example_group_hierarchy.rb new file mode 100644 index 000000000..f2c9fb5cd --- /dev/null +++ b/vendor/gems/rspec-1.3.1/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/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb new file mode 100644 index 000000000..93f459587 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb @@ -0,0 +1,287 @@ +module Spec + module Example + + module ExampleGroupMethods + class << self + attr_accessor :matcher_class + + def build_description_from(*args) + text = args.inject("") do |description, arg| + description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/) + description << arg.to_s + end + text == "" ? nil : text + end + end + + include Spec::Example::BeforeAndAfterHooks + include Spec::Example::Subject::ExampleGroupMethods + include Spec::Example::PredicateMatchers + 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 + # describe Stack, "with no elements" + # + # before + # @stack = Stack.new + # end + # + # it "should raise on pop" do + # lambda{ @stack.pop }.should raise_error + # end + # end + # + def describe(*args, &example_group_block) + raise Spec::Example::NoDescriptionError.new("example group", caller(0)[1]) if args.empty? + if example_group_block + options = add_options(args) + set_location(options, caller(0)[1]) + if options[:shared] + ExampleGroupFactory.create_shared_example_group(*args, &example_group_block) + else + subclass(*args, &example_group_block) + end + else + set_description(*args) + 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) + example_proxy = ExampleProxy.new(description, options, backtrace || caller(0)[1]) + example_proxies << example_proxy + example_implementations[example_proxy] = implementation || pending_implementation + example_proxy + end + + def pending_implementation + lambda {|*args| raise(Spec::Example::NotYetImplementedError) } + end + + alias_method :it, :example + alias_method :specify, :example + + # Use this to temporarily disable an example. + 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? + return true if examples.empty? + return dry_run(examples, run_options) if run_options.dry_run? + + define_methods_from_predicate_matchers + + success, before_all_instance_variables = run_before_all(run_options) + success, after_all_instance_variables = run_examples(success, before_all_instance_variables, examples, run_options) + success = run_after_all(success, after_all_instance_variables, run_options) + end + + def set_description(*args) + @description_args, @options = args_and_options(*args) + @backtrace = caller(1) + @location = File.expand_path(options[:location]) if options[:location] + self + end + + def notify(reporter) # :nodoc: + reporter.example_group_started(ExampleGroupProxy.new(self)) + end + + 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 + + def number_of_examples #:nodoc: + example_proxies.length + end + + 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 + + def let(name, &block) + define_method name do + @assignments ||= {} + @assignments[name] ||= instance_eval(&block) + end + end + + def let!(name, &block) + let(name, &block) + before { __send__(name) } + end + + private + + def subclass(*args, &example_group_block) + @class_count ||= 0 + @class_count += 1 + klass = const_set("Subclass_#{@class_count}", Class.new(self)) + klass.set_description(*args) + klass.include_constants_in(args.last[:scope]) + klass.module_eval(&example_group_block) + klass + end + + def dry_run(examples, run_options) + examples.each do |example| + run_options.reporter.example_started(example) + run_options.reporter.example_finished(example) + end + end + + def run_before_all(run_options) + return [true,{}] if example_group_hierarchy.before_all_parts.empty? + example_proxy = ExampleProxy.new("before(:all)") + before_all = new(example_proxy) + begin + example_group_hierarchy.run_before_all(before_all) + return [true, before_all.instance_variable_hash] + rescue Exception => e + run_options.reporter.example_failed(example_proxy, e) + return [false, before_all.instance_variable_hash] + end + end + + 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)") + after_all = new(example_proxy) + after_all.set_instance_variables_from_hash(instance_variables) + example_group_hierarchy.run_after_all(after_all) + success + rescue Exception => e + 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) + if run_options.line_number_requested? + if location =~ /:#{run_options.example_line}:?/ + example_proxies + else + example_proxies.select {|proxy| proxy.location =~ /:#{run_options.example_line}:?/} + end + else + example_proxies.reject do |proxy| + matcher = ExampleGroupMethods.matcher_class. + new(description.to_s, proxy.description) + !matcher.matches?(run_options.examples) + end + end + end + + def examples_were_specified?(run_options) + !run_options.examples.empty? + end + + 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 + + def should_method?(method_name) + !(method_name =~ /^should(_not)?$/) && + method_name =~ /^should/ && + instance_method(method_name).arity < 1 + end + + def include_shared_example_group(shared_example_group) + case shared_example_group + when SharedExampleGroup + include shared_example_group + else + unless example_group = SharedExampleGroup.find(shared_example_group) + raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found") + end + include(example_group) + end + end + end + + end +end diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/example_group_proxy.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/example_group_proxy.rb new file mode 100644 index 000000000..3c258d61f --- /dev/null +++ b/vendor/gems/rspec-1.3.1/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/gems/rspec-1.3.1/lib/spec/example/example_matcher.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/example_matcher.rb new file mode 100644 index 000000000..3acd7e14a --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/example_matcher.rb @@ -0,0 +1,43 @@ +module Spec + module Example + class ExampleMatcher + 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}$)/ + end + + def matches_example_not_considering_modules?(specified_example) + specified_example =~ /(^#{example_group_regex_not_considering_modules} #{example_regexp}$|^#{example_group_regex_not_considering_modules}$|^#{example_regexp}$)/ + end + + def example_group_regex + Regexp.escape(@example_group_description) + end + + def example_group_with_before_all_regexp + Regexp.escape("#{@example_group_description} before(:all)") + end + + def example_group_regex_not_considering_modules + Regexp.escape(@example_group_description.split('::').last) + end + + def example_regexp + Regexp.escape(@example_name) if @example_name + end + end + + ExampleGroupMethods.matcher_class = ExampleMatcher + end +end diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/example_methods.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/example_methods.rb new file mode 100644 index 000000000..10f45a722 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/example_methods.rb @@ -0,0 +1,152 @@ +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 + + # Declared description for this example: + # + # describe Account do + # it "should start with a balance of 0" do + # ... + # + # description + # => "should start with a balance of 0" + def description + if description = @_proxy.description || ::Spec::Matchers.generated_description + description + else + Spec.warn Spec::Example::NoDescriptionError.message("example", @_proxy.location) + end + end + + def options # :nodoc: + @_proxy.options + end + + 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 + before_each_example + instance_eval(&@_implementation) + rescue Interrupt + exit 1 + rescue Exception => e + execution_error ||= e + end + begin + after_each_example + rescue Interrupt + exit 1 + rescue Exception => e + execution_error ||= e + end + end + + 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: + # + # expect { this_block }.to change{this.expression}.from(old_value).to(new_value) + # expect { this_block }.to raise_error + def expect(&block) + block.extend BlockAliases + end + + def eval_each_fail_fast(blocks) # :nodoc: + blocks.each {|block| instance_eval(&block)} + end + + def eval_each_fail_slow(blocks) # :nodoc: + first_exception = nil + blocks.each do |block| + begin + instance_eval(&block) + rescue Exception => e + first_exception ||= e + end + end + raise first_exception if first_exception + end + + def instance_variable_hash # :nodoc: + instance_variables.inject({}) do |variable_hash, variable_name| + variable_hash[variable_name] = instance_variable_get(variable_name) + variable_hash + end + end + + def set_instance_variables_from_hash(ivars) # :nodoc: + ivars.each do |variable_name, value| + # Ruby 1.9 requires variable.to_s on the next line + unless ['@_proxy', '@_implementation', '@method_name'].include?(variable_name.to_s) + instance_variable_set variable_name, value + end + end + end + + # Run all the before(:each) blocks for this example + def run_before_each + example_group_hierarchy.run_before_each(self) + end + + # Run all the after(:each) blocks for this example + def run_after_each + example_group_hierarchy.run_after_each(self) + end + + def initialize(example_proxy, &implementation) + @_proxy = example_proxy + @_implementation = implementation + @_backtrace = caller + end + + private + + include Matchers + include Pending + + def before_each_example + setup_mocks_for_rspec + run_before_each + end + + def after_each_example + run_after_each + verify_mocks_for_rspec + ensure + teardown_mocks_for_rspec + end + + def described_class + self.class.described_class + end + + def description_args + self.class.description_args + end + + def example_group_hierarchy + self.class.example_group_hierarchy + end + + end + end +end diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/example_proxy.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/example_proxy.rb new file mode 100644 index 000000000..f726d0e70 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/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/gems/rspec-1.3.1/lib/spec/example/module_reopening_fix.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/module_reopening_fix.rb new file mode 100644 index 000000000..9ea088a2e --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/module_reopening_fix.rb @@ -0,0 +1,43 @@ +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> + # from (irb):12 + module ModuleReopeningFix + def child_modules + @child_modules ||= [] + end + + def included(mod) + child_modules << mod + end + + def include(mod) + super + child_modules.each do |child_module| + child_module.__send__(:include, mod) + end + end + end + end +end diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/pending.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/pending.rb new file mode 100644 index 000000000..9aad1aab0 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/pending.rb @@ -0,0 +1,18 @@ +module Spec + module Example + module Pending + def pending(message = "TODO") + if block_given? + begin + yield + rescue Exception + raise Spec::Example::ExamplePendingError.new(message) + end + raise Spec::Example::PendingExampleFixedError.new("Expected pending '#{message}' to fail. No Error was raised.") + else + raise Spec::Example::ExamplePendingError.new(message) + end + end + end + end +end diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/predicate_matchers.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/predicate_matchers.rb new file mode 100644 index 000000000..c3c319519 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/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/gems/rspec-1.3.1/lib/spec/example/shared_example_group.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/shared_example_group.rb new file mode 100644 index 000000000..336944914 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/shared_example_group.rb @@ -0,0 +1,59 @@ +module Spec + module Example + class SharedExampleGroup < Module + module ClassMethods + def register(*args, &block) + new_example_group = new(*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 + + 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 + return true if new_example_group.equal?(existing_example_group) + return true if expanded_path(new_example_group) == expanded_path(existing_example_group) + raise ArgumentError.new("Shared Example '#{existing_example_group.description}' already exists") + end + + def expanded_path(example_group) + File.expand_path(example_group.location) + end + end + + extend ClassMethods + include ExampleGroupMethods + + def initialize(*args, &example_group_block) + set_description(*args) + @example_group_block = example_group_block + end + + def included(mod) # :nodoc: + mod.module_eval(&@example_group_block) + end + end + end +end diff --git a/vendor/gems/rspec-1.3.1/lib/spec/example/subject.rb b/vendor/gems/rspec-1.3.1/lib/spec/example/subject.rb new file mode 100644 index 000000000..4f53f543a --- /dev/null +++ b/vendor/gems/rspec-1.3.1/lib/spec/example/subject.rb @@ -0,0 +1,114 @@ +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 + example do + self.class.class_eval do + define_method(:subject) do + super().send(attribute) + end + end + instance_eval(&block) + end + 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 ? proc {described_class.new} : proc {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 |