Module Spec::DSL::BehaviourEval::ModuleMethods
In: lib/spec/dsl/behaviour_eval.rb

Methods

Included Modules

BehaviourCallbacks

Attributes

behaviour  [W] 
description  [RW] 

Public Instance methods

You can pass this one or many modules. Each module will subsequently be included in the each object in which an example is run. Use this to provide global helper methods to your examples.

Example

  module HelperMethods
    def helper_method
      ...
    end
  end

  describe Thing do
    include HelperMethods
    it "should do stuff" do
      helper_method
    end
  end

[Source]

    # File lib/spec/dsl/behaviour_eval.rb, line 42
42:         def include(*mods)
43:           mods.each do |mod|
44:             included_modules << mod
45:             mod.send :included, self
46:           end
47:         end

RSpec runs every example in a new instance of Object, mixing in the behaviour necessary to run examples. Because this behaviour gets mixed in, it can get mixed in to an instance of any class at all.

This is something that you would hardly ever use, but there is one common use case for it - inheriting from Test::Unit::TestCase. RSpec‘s Rails plugin uses this feature to provide access to all of the features that are available for Test::Unit within RSpec examples.

[Source]

    # File lib/spec/dsl/behaviour_eval.rb, line 18
18:         def inherit(klass)
19:           raise ArgumentError.new("Shared behaviours cannot inherit from classes") if @behaviour.shared?
20:           @behaviour_superclass = klass
21:           derive_execution_context_class_from_behaviour_superclass
22:         end

Creates an instance of Spec::DSL::Example and adds it to a collection of examples of the current behaviour.

[Source]

     # File lib/spec/dsl/behaviour_eval.rb, line 116
116:         def it(description=:__generate_description, opts={}, &block)
117:           examples << Example.new(description, opts, &block)
118:         end

Use this to pull in examples from shared behaviours. See Spec::Runner for information about shared behaviours.

[Source]

    # File lib/spec/dsl/behaviour_eval.rb, line 51
51:         def it_should_behave_like(behaviour_description)
52:           behaviour = @behaviour.class.find_shared_behaviour(behaviour_description)
53:           if behaviour.nil?
54:             raise RuntimeError.new("Shared Behaviour '#{behaviour_description}' can not be found")
55:           end
56:           behaviour.copy_to(self)
57:         end

Dynamically generates a custom matcher that will match a predicate on your class. RSpec provides a couple of these out of the box:

  exist (or state expectations)
    File.should exist("path/to/file")

  an_instance_of (for mock argument constraints)
    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

[Source]

    # File lib/spec/dsl/behaviour_eval.rb, line 97
97:         def predicate_matchers
98:           @predicate_matchers ||= {:exist => :exist?, :an_instance_of => :is_a?}
99:         end

Alias for it.

[Source]

     # File lib/spec/dsl/behaviour_eval.rb, line 121
121:         def specify(description=:__generate_description, opts={}, &block)
122:           it(description, opts, &block)
123:         end

Protected Instance methods

[Source]

     # File lib/spec/dsl/behaviour_eval.rb, line 149
149:         def after_all_proc(behaviour_type, &error_handler)
150:           parts = []
151:           parts.push(*after_all_parts(behaviour_type)) unless behaviour_type.nil?
152:           parts.push(*after_all_parts(nil))
153:           parts.push(*Behaviour.after_all_parts(behaviour_type)) unless behaviour_type.nil?
154:           parts.push(*Behaviour.after_all_parts(nil))
155:           CompositeProcBuilder.new(parts).proc(&error_handler)
156:         end

[Source]

     # File lib/spec/dsl/behaviour_eval.rb, line 167
167:         def after_each_proc(behaviour_type, &error_handler)
168:           parts = []
169:           parts.push(*after_each_parts(behaviour_type)) unless behaviour_type.nil?
170:           parts.push(*after_each_parts(nil))
171:           parts.push(*Behaviour.after_each_parts(behaviour_type)) unless behaviour_type.nil?
172:           parts.push(*Behaviour.after_each_parts(nil))
173:           CompositeProcBuilder.new(parts).proc(&error_handler)
174:         end

[Source]

     # File lib/spec/dsl/behaviour_eval.rb, line 140
140:         def before_all_proc(behaviour_type, &error_handler)
141:           parts = []
142:           parts.push(*Behaviour.before_all_parts(nil))
143:           parts.push(*Behaviour.before_all_parts(behaviour_type)) unless behaviour_type.nil?
144:           parts.push(*before_all_parts(nil))
145:           parts.push(*before_all_parts(behaviour_type)) unless behaviour_type.nil?
146:           CompositeProcBuilder.new(parts).proc(&error_handler)
147:         end

[Source]

     # File lib/spec/dsl/behaviour_eval.rb, line 158
158:         def before_each_proc(behaviour_type, &error_handler)
159:           parts = []
160:           parts.push(*Behaviour.before_each_parts(nil))
161:           parts.push(*Behaviour.before_each_parts(behaviour_type)) unless behaviour_type.nil?
162:           parts.push(*before_each_parts(nil))
163:           parts.push(*before_each_parts(behaviour_type)) unless behaviour_type.nil?
164:           CompositeProcBuilder.new(parts).proc(&error_handler)
165:         end

[Source]

     # File lib/spec/dsl/behaviour_eval.rb, line 197
197:         def examples
198:           @examples ||= []
199:         end

[Source]

     # File lib/spec/dsl/behaviour_eval.rb, line 193
193:         def included_modules
194:           @included_modules ||= [::Spec::Matchers]
195:         end

[Source]

     # File lib/spec/dsl/behaviour_eval.rb, line 133
133:         def method_missing(method_name, *args)
134:           if behaviour_superclass.respond_to?(method_name)
135:             return execution_context_class.send(method_name, *args)
136:           end
137:           super
138:         end

[Validate]