Class: RSpec::Abq::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/abq/test_case.rb

Overview

ABQ’s representation of a test case

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, tags, meta) ⇒ TestCase

Returns a new instance of TestCase.



5
6
7
8
9
10
11
# File 'lib/rspec/abq/test_case.rb', line 5

def initialize(id, tags, meta)
  @id = id
  @tags = tags
  @meta = meta
  @rerun_file_path, scoped_id = RSpec::Core::Example.parse_id @id
  @scope = self.class.parse_scope(scoped_id || "")
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/rspec/abq/test_case.rb', line 13

def id
  @id
end

#metaObject (readonly)

Returns the value of attribute meta.



15
16
17
# File 'lib/rspec/abq/test_case.rb', line 15

def meta
  @meta
end

#rerun_file_pathObject (readonly)

Returns the value of attribute rerun_file_path.



16
17
18
# File 'lib/rspec/abq/test_case.rb', line 16

def rerun_file_path
  @rerun_file_path
end

#scoped_idObject (readonly)

Returns the value of attribute scoped_id.



17
18
19
# File 'lib/rspec/abq/test_case.rb', line 17

def scoped_id
  @scoped_id
end

#tagsObject (readonly)

Returns the value of attribute tags.



14
15
16
# File 'lib/rspec/abq/test_case.rb', line 14

def tags
  @tags
end

Class Method Details

.end_markerObject

Faux test case to mark end of all tests. Will never match any group or test ID, since the scoped_id is empty.



68
69
70
# File 'lib/rspec/abq/test_case.rb', line 68

def self.end_marker
  @end_marker ||= TestCase.new("[]", [], {})
end

.parse_scope(scope) ⇒ Object

Parses a scope n:m:q:r into [n, m, q, r] Invariant of RSpec is that a scope n:m:q:r is contained in a scope n:m:q



21
22
23
# File 'lib/rspec/abq/test_case.rb', line 21

def self.parse_scope(scope)
  scope.split(":")
end

.scope_contains(outer, inner) ⇒ Object

‘scope_contains outer inner` is true iff the inner scope is deeper than the outer scope.

Parameters:

  • outer (Array<String>)

    parsed scope

  • inner (Array<String>)

    parsed scope



30
31
32
# File 'lib/rspec/abq/test_case.rb', line 30

def self.scope_contains(outer, inner)
  inner.take(outer.length) == outer
end

.scope_leftover(outer, inner) ⇒ Object

‘scope_leftover outer inner` returns the partial scopes of `inner` that are deeper than `outer`.

Parameters:

  • outer (Array<String>)

    parsed scope

  • inner (Array<String>)

    parsed scope



39
40
41
# File 'lib/rspec/abq/test_case.rb', line 39

def self.scope_leftover(outer, inner)
  inner[outer.length..] || []
end

Instance Method Details

#directly_in_group?(group) ⇒ Boolean

Parameters:

  • group (RSpec::Core::ExampleGroup)

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
# File 'lib/rspec/abq/test_case.rb', line 52

def directly_in_group?(group)
  return false unless in_group?(group)

  group_scope = self.class.parse_scope(group.[:scoped_id])
  additional_scoping = self.class.scope_leftover(group_scope, @scope)
  raise "#{@id} not inside #{group_scope}, but we thought it was" if additional_scoping.empty?
  additional_scoping.length == 1
end

#in_group?(group) ⇒ Boolean

Parameters:

  • group (RSpec::Core::ExampleGroup)

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/rspec/abq/test_case.rb', line 44

def in_group?(group)
  return false if group.[:rerun_file_path] != @rerun_file_path

  group_scope = self.class.parse_scope(group.[:scoped_id])
  self.class.scope_contains(group_scope, @scope)
end

#is_example?(example) ⇒ Boolean

Parameters:

  • example (RSpec::Core::Example)

Returns:

  • (Boolean)


62
63
64
# File 'lib/rspec/abq/test_case.rb', line 62

def is_example?(example)
  example.[:rerun_file_path] == @rerun_file_path && self.class.parse_scope(example.[:scoped_id]) == @scope
end