Module: RSpec::RequestableExamples

Includes:
Core::SharedExampleGroup
Defined in:
lib/rspec/requestable-examples/version.rb,
lib/rspec/requestable-examples.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Version Classes: RequestedExamples

Instance Method Summary collapse

Instance Method Details

#examples_that_can_be_requestedObject



39
40
41
# File 'lib/rspec/requestable-examples.rb', line 39

def examples_that_can_be_requested
  @examples_that_can_be_requested ||= []
end

#request_examples(options) ⇒ Object



43
44
45
# File 'lib/rspec/requestable-examples.rb', line 43

def request_examples(options)
  @requested_examples = RequestedExamples.new(options)
end

#requestable_describe(description, options = {}, &blk) ⇒ Object Also known as: requestable_context



58
59
60
61
62
# File 'lib/rspec/requestable-examples.rb', line 58

def requestable_describe(description, options={}, &blk)
  label = options[:as] || description
  examples_that_can_be_requested << label
  describe description, &blk if requested_examples.run?(label)
end

#requestable_example(description, options = {}, &blk) ⇒ Object Also known as: requestable_it



51
52
53
54
55
# File 'lib/rspec/requestable-examples.rb', line 51

def requestable_example(description, options={}, &blk)
  label = options[:as] || description
  examples_that_can_be_requested << label
  it description, &blk if requested_examples.run?(label)
end

#requestable_examples(*args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rspec/requestable-examples.rb', line 19

def requestable_examples(*args, &block)
  if [String, Symbol, Module].any? {|cls| cls === args.first }
    object = args.shift
    ensure_shared_example_group_name_not_taken(object)
    RSpec.world.shared_example_groups[object] = lambda do |options={}|
      request_examples options
      instance_eval(&block)
      verify_requested_examples!
    end
  end
  
  unless args.empty?
    mod = Module.new
    (class << mod; self; end).send(:define_method, :extended) do |host|
      host.class_eval(&block)
    end
    RSpec.configuration.extend(mod, *args)
  end
end

#requested_examplesObject



47
48
49
# File 'lib/rspec/requestable-examples.rb', line 47

def requested_examples
  @requested_examples
end

#verify_requested_examples!Object



65
66
67
68
69
70
71
72
# File 'lib/rspec/requestable-examples.rb', line 65

def verify_requested_examples!
  missing_examples = requested_examples - examples_that_can_be_requested
  missing_examples.each do |description|
    it description do
      pending("This example was requested but isn't defined, typo?")
    end
  end
end