Class: Spec::DSL::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/dsl/configuration.rb

Instance Method Summary collapse

Instance Method Details

#append_after(*args, &proc) ⇒ Object

Appends a global after block to all behaviours. See #append_before for filtering semantics.



123
124
125
# File 'lib/spec/dsl/configuration.rb', line 123

def append_after(*args, &proc)
  Behaviour.append_after(*args, &proc)
end

#append_before(*args, &proc) ⇒ Object Also known as: before

Appends a global before block to all behaviours.

If you want to restrict the block to a subset of all the behaviours then specify this in a Hash as the last argument:

config.prepend_before(:all, :behaviour_type => :farm)

or

config.prepend_before(:behaviour_type => :farm)


110
111
112
# File 'lib/spec/dsl/configuration.rb', line 110

def append_before(*args, &proc)
  Behaviour.append_before(*args, &proc)
end

#exclude(*modules) ⇒ Object

This is just for cleanup in RSpec’s own examples



76
77
78
79
80
# File 'lib/spec/dsl/configuration.rb', line 76

def exclude(*modules) #:nodoc:
  @modules.each do |behaviour_type, mods|
    modules.each{|m| mods.delete(m)}
  end
end

#include(*args) ⇒ Object

Declares modules to be included in all behaviours (describe blocks).

config.include(My::Bottle, My::Cup)

If you want to restrict the inclusion to a subset of all the behaviours then specify this in a Hash as the last argument:

config.include(My::Pony, My::Horse, :behaviour_type => :farm)

Only behaviours that have that type will get the modules included:

describe "Downtown", :behaviour_type => :city do
  # Will *not* get My::Pony and My::Horse included
end

describe "Old Mac Donald", :behaviour_type => :farm do
  # *Will* get My::Pony and My::Horse included
end


58
59
60
61
62
63
64
65
66
# File 'lib/spec/dsl/configuration.rb', line 58

def include(*args)
  args << {} unless Hash === args.last
  modules, options = args_and_options(*args)
  required_behaviour_type = options[:behaviour_type]
  required_behaviour_type = required_behaviour_type.to_sym unless required_behaviour_type.nil?
  @modules ||= {}
  @modules[required_behaviour_type] ||= []
  @modules[required_behaviour_type] += modules
end

#mock_frameworkObject

:nodoc:



35
36
37
# File 'lib/spec/dsl/configuration.rb', line 35

def mock_framework # :nodoc:
  @mock_framework ||= mock_framework_path("rspec")
end

#mock_with(mock_framework) ⇒ Object

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 setup_mocks_for_rspec, verify_mocks_for_rspec and 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


26
27
28
29
30
31
32
33
# File 'lib/spec/dsl/configuration.rb', line 26

def mock_with(mock_framework)
  @mock_framework = case mock_framework
  when Symbol
    mock_framework_path(mock_framework.to_s)
  else
    mock_framework
  end
end

#modules_for(required_behaviour_type) ⇒ Object

:nodoc:



68
69
70
71
72
73
# File 'lib/spec/dsl/configuration.rb', line 68

def modules_for(required_behaviour_type) #:nodoc:
  @modules ||= {}
  modules = @modules[nil] || [] # general ones
  modules << @modules[required_behaviour_type.to_sym] unless required_behaviour_type.nil?
  modules.uniq.compact
end

#predicate_matchersObject

Defines global predicate matchers. Example:

config.predicate_matchers[:swim] = :can_swim?

This makes it possible to say:

person.should swim # passes if person.should_swim? returns true


90
91
92
# File 'lib/spec/dsl/configuration.rb', line 90

def predicate_matchers
  @predicate_matchers ||= {}
end

#prepend_after(*args, &proc) ⇒ Object Also known as: after

Prepends a global after block to all behaviours. See #append_before for filtering semantics.



117
118
119
# File 'lib/spec/dsl/configuration.rb', line 117

def prepend_after(*args, &proc)
  Behaviour.prepend_after(*args, &proc)
end

#prepend_before(*args, &proc) ⇒ Object

Prepends a global before block to all behaviours. See #append_before for filtering semantics.



96
97
98
# File 'lib/spec/dsl/configuration.rb', line 96

def prepend_before(*args, &proc)
  Behaviour.prepend_before(*args, &proc)
end