Module: RSpecOutlines::ExampleGroup::ClassMethods
- Defined in:
- lib/rspec_outlines.rb
Instance Attribute Summary collapse
-
#current_outline_binding ⇒ Object
readonly
Returns the value of attribute current_outline_binding.
-
#current_outline_example_counter ⇒ Object
readonly
Returns the value of attribute current_outline_example_counter.
Instance Method Summary collapse
- #current_outline ⇒ Object
- #fields(*names) ⇒ Object
- #instance_eval_with_outline_binding(outline_binding, &block) ⇒ Object
- #outline(name = nil, &definition) ⇒ Object
- #outline_example_name(name) ⇒ Object
- #values(*args) ⇒ Object
Instance Attribute Details
#current_outline_binding ⇒ Object (readonly)
Returns the value of attribute current_outline_binding.
59 60 61 |
# File 'lib/rspec_outlines.rb', line 59 def current_outline_binding @current_outline_binding end |
#current_outline_example_counter ⇒ Object (readonly)
Returns the value of attribute current_outline_example_counter.
59 60 61 |
# File 'lib/rspec_outlines.rb', line 59 def current_outline_example_counter @current_outline_example_counter end |
Instance Method Details
#current_outline ⇒ Object
20 21 22 |
# File 'lib/rspec_outlines.rb', line 20 def current_outline @current_outline ||= nil end |
#fields(*names) ⇒ Object
24 25 26 27 28 |
# File 'lib/rspec_outlines.rb', line 24 def fields(*names) current_outline or raise Error, "no outline defined" current_outline.fields = names end |
#instance_eval_with_outline_binding(outline_binding, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rspec_outlines.rb', line 34 def instance_eval_with_outline_binding(outline_binding, &block) original_outline_binding = @current_outline_binding @current_outline_binding = outline_binding @current_outline_example_counter += 1 begin instance_eval(&block) ensure @current_outline_binding = original_outline_binding end end |
#outline(name = nil, &definition) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/rspec_outlines.rb', line 10 def outline(name=nil, &definition) if name outline_body = lambda { |x| it(outline_example_name(name), &definition) } else outline_body = definition end @current_outline = Outline.new(self, &outline_body) @current_outline_example_counter = 0 end |
#outline_example_name(name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rspec_outlines.rb', line 45 def outline_example_name(name) name = name.dup changed = name.gsub!(/:(?:(\w+|#)|\{(\w+)\})/) do field = $1 || $2 if field == '#' current_outline_example_counter else current_outline_binding[field.to_sym] end end # Give specs have unique names by default. changed ? name : outline_example_name("#{name} (:#)") end |
#values(*args) ⇒ Object
30 31 32 |
# File 'lib/rspec_outlines.rb', line 30 def values(*args) current_outline.eval(*args) end |