Module: Assert::Context::TestDSL

Included in:
Assert::Context
Defined in:
lib/assert/context/test_dsl.rb

Instance Method Summary collapse

Instance Method Details

#should(desc_or_macro, called_from = nil, first_caller = nil, &block) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/assert/context/test_dsl.rb', line 62

def should(desc_or_macro, called_from = nil, first_caller = nil, &block)
  unless desc_or_macro.is_a?(Assert::Macro)
    desc_or_macro = "should #{desc_or_macro}"
  end
  test(
    desc_or_macro,
    called_from,
    first_caller || caller_locations.first,
    &block
  )
end

#should_eventually(desc_or_macro, called_from = nil, first_caller = nil, &block) ⇒ Object Also known as: should_skip



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/assert/context/test_dsl.rb', line 74

def should_eventually(
      desc_or_macro,
      called_from = nil,
      first_caller = nil,
      &block)
  unless desc_or_macro.is_a?(Assert::Macro)
    desc_or_macro = "should #{desc_or_macro}"
  end
  test_eventually(
    desc_or_macro,
    called_from,
    first_caller || caller_locations.first,
    &block
  )
end

#test(desc_or_macro, called_from = nil, first_caller = nil, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/assert/context/test_dsl.rb', line 12

def test(desc_or_macro, called_from = nil, first_caller = nil, &block)
  if desc_or_macro.is_a?(Assert::Macro)
    instance_eval(&desc_or_macro)
  elsif block_given?
    # create a test from the given code block
    desc =
      if desc_or_macro.is_a?(Assert::Macro)
        desc_or_macro.name
      else
        desc_or_macro
      end
    suite.on_test(
      Assert::Test.for_block(
        desc,
        Assert::ContextInfo.new(
          self,
          called_from,
          first_caller || caller_locations.first,
        ),
        suite.config,
        &block
      ),
    )
  else
    test_eventually(
      desc_or_macro,
      called_from,
      first_caller || caller_locations.first,
      &block
    )
  end
end

#test_eventually(desc_or_macro, called_from = nil, first_caller = nil) ⇒ Object Also known as: test_skip



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/assert/context/test_dsl.rb', line 45

def test_eventually(desc_or_macro, called_from = nil, first_caller = nil)
  # create a test from a proc that just skips
  ci =
    Assert::ContextInfo.new(
      self,
      called_from,
      first_caller || caller_locations.first,
    )
  suite.on_test(Assert::Test.for_block(
    desc_or_macro.is_a?(Assert::Macro) ? desc_or_macro.name : desc_or_macro,
    ci,
    suite.config,
    &proc{ skip("TODO", [ci.called_from.to_s]) }
  ))
end