class Aygabtu::ScopeActor

Public Class Methods

actions() click to toggle source
# File lib/aygabtu/scope_actor.rb, line 11
def self.actions
  [:visit_with, :visit, :pend, :ignore, :covered!]
end
new(scope, example_group) click to toggle source
# File lib/aygabtu/scope_actor.rb, line 7
def initialize(scope, example_group)
  @scope, @example_group = scope, example_group
end

Public Instance Methods

covered!() click to toggle source
# File lib/aygabtu/scope_actor.rb, line 44
def covered!
  ignore "this is already covered by a non-aygabtu feature"
end
ignore(reason) click to toggle source
# File lib/aygabtu/scope_actor.rb, line 32
def ignore(reason)
  raise "Reason for ignoring must be a string" unless reason.is_a?(String)

  each_empty_scope_segment do |scope, generator|
    generator.generate_no_match_failing_example(:ignore)
  end

  each_scope_segment_and_route do |scope, generator, route|
    mark_route(route, :ignore)
  end
end
pend(reason) click to toggle source
# File lib/aygabtu/scope_actor.rb, line 48
def pend(reason)
  each_empty_scope_segment do |scope, generator|
    generator.generate_no_match_failing_example(:pend)
  end

  each_scope_segment_and_route do |scope, generator, route|
    mark_route(route, :pend)
    generator.generate_pending_example(route, reason)
  end
end
visit() click to toggle source
# File lib/aygabtu/scope_actor.rb, line 28
def visit
  visit_with({})
end
visit_with(visiting_data) click to toggle source
# File lib/aygabtu/scope_actor.rb, line 15
def visit_with(visiting_data)
  each_empty_scope_segment do |scope, generator|
    generator.generate_no_match_failing_example(:visit)
  end

  each_scope_segment_and_route do |scope, generator, route|
    visiting_data = @scope.visiting_data.merge(visiting_data)

    mark_route(route, :visit)
    generator.generate_example(route, visiting_data)
  end
end

Private Instance Methods

each_empty_scope_segment() { |segment, generator| ... } click to toggle source
# File lib/aygabtu/scope_actor.rb, line 86
def each_empty_scope_segment
  segments_generators_routes.each do |segment, generator, routes|
    next unless routes.empty?

    yield segment, generator
  end
end
each_scope_segment_and_route() { |segment, generator, route| ... } click to toggle source
# File lib/aygabtu/scope_actor.rb, line 80
def each_scope_segment_and_route
  segments_generators_routes.each do |segment, generator, routes|
    routes.each { |route| yield segment, generator, route }
  end
end
mark_route(route, action) click to toggle source
# File lib/aygabtu/scope_actor.rb, line 61
def mark_route(route, action)
  checkpoint = @example_group.aygabtu_handle.generate_checkpoint
  mark = RouteMark.new(action, PointOfCall.point_of_call, checkpoint)

  conflicting_marks = route.conflicting_marks(mark)
  if conflicting_marks.any?
    conflict_strings = conflicting_marks.map(&:description)
    raise "Action #{action} for #{route.inspect} conflicts with #{conflict_strings.join ", "}"
  else
    route.marks.push mark
  end
end
route_action_valid?(route, action) click to toggle source
# File lib/aygabtu/scope_actor.rb, line 74
def route_action_valid?(route, action)
  previous_actions_considered = route.marks.keys
  previous_actions_considered.delete(:visit) if action == :visit # creating more than one :visit example per route is allowed
  route.marks.values_at(*previous_actions_considered).all?(&:empty?)
end
segments_generators_routes() click to toggle source
# File lib/aygabtu/scope_actor.rb, line 94
def segments_generators_routes
  @segments_and_generators ||= @scope.segments.map do |segment|
    generator = Generator.new(segment, @example_group)

    routes = @example_group.aygabtu_matching_routes(segment)

    [segment, generator, routes]
  end
end