Class: Totes::Spec
- Inherits:
-
Object
- Object
- Totes::Spec
- Defined in:
- lib/totes/spec.rb
Defined Under Namespace
Classes: SkipQuery
Constant Summary collapse
- StartOver =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #describe(*args, &block) ⇒ Object
-
#initialize(*args, &block) ⇒ Spec
constructor
A new instance of Spec.
-
#it ⇒ Object
(also: #its)
returns the subject query object.
-
#method_missing(*args, &block) ⇒ Object
builds the matchers.
Constructor Details
#initialize(*args, &block) ⇒ Spec
Returns a new instance of Spec.
7 8 9 10 11 12 13 14 15 |
# File 'lib/totes/spec.rb', line 7 def initialize(*args, &block) @subject = __get_subject__(*args) @__block = block @__specs = [] # inner specs list @__count = { queries: 0, # global queries counter current: 0 # the current query marker } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
builds the matchers
40 41 42 |
# File 'lib/totes/spec.rb', line 40 def method_missing(*args, &block) Totes::Matcher.build(*args, &block) || super(*args, &block) end |
Instance Attribute Details
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
3 4 5 |
# File 'lib/totes/spec.rb', line 3 def subject @subject end |
Instance Method Details
#describe(*args, &block) ⇒ Object
17 18 19 20 21 |
# File 'lib/totes/spec.rb', line 17 def describe(*args, &block) @__specs << self.class.new(*args, &block).tap do |spec| spec.instance_variable_set("@__count", @__count) end end |
#it ⇒ Object Also known as: its
returns the subject query object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/totes/spec.rb', line 24 def it if @__count[:current] == @__count[:queries] @__count[:queries] += 1 Totes::Query.new(@subject) # going in for real elsif @__count[:current] > @__count[:queries] @__count[:queries] += 1 SkipQuery.new # rerunning through a previous query, skipping else @__count[:current] += 1 # switching to the next query raise StartOver end end |