Class: RSpec::Versioned

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/versioned.rb

Class Method Summary collapse

Class Method Details

.applyObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rspec/versioned.rb', line 7

def self.apply
  RSpec.configure do |config|
    config.add_setting :notify_version_number, :default => false
    config.add_setting :clear_lets_on_failure, :default => true

    fetch_current_example = RSpec.respond_to?(:current_example) ?
      proc { RSpec.current_example } : proc { |context| context.example }

    config.around(:each) do |p| # example is a Proc extended with Procsy
      notify_version_number = p.[:notify_version_number] || RSpec.configuration.notify_version_number

      run_example = Proc.new do |v, uri|
        current_example = fetch_current_example.call(self)
        current_example.clear_exceptions
        p.[:versioned] = {number:v, uri:uri}
        p.run
        RSpec.configuration.reporter.message("RSpec::Versioned testing /v#{v}") if notify_version_number
      end

      if p..has_key?(:versions)
        if p.[:versions][:base_uri] || (VersionedBlocks.base_uri && VersionedBlocks.base_uri!='') # we have a URI
          versioned_block(p.[:versions]) do |v, uri|
            run_example.call v,uri
          end
        else # we don't have a URI
          versioned_block(p.[:versions]) do |v|
            run_example.call v
          end
        end
      else # didn't specify any versions...just run the test!
        p.run
      end
      self.clear_lets if clear_lets
    end
  end
end