class Totes::Spec

Constants

StartOver

Attributes

subject[R]

Public Class Methods

new(*args, &block) click to toggle source
# 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

Public Instance Methods

describe(*args, &block) click to toggle source
# 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() click to toggle source

returns the subject query object

# 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
Also aliased as: its
its()
Alias for: it
method_missing(*args, &block) click to toggle source

builds the matchers

Calls superclass method
# File lib/totes/spec.rb, line 40
def method_missing(*args, &block)
  Totes::Matcher.build(*args, &block) || super(*args, &block)
end

Private Instance Methods

__get_subject__(*args) click to toggle source
# File lib/totes/spec.rb, line 46
def __get_subject__(*args)
  return args[0] # TODO make it smarter
end