Class: RSpock::AST::Parser::ExpectBlock

Inherits:
Block
  • Object
show all
Defined in:
lib/rspock/ast/parser/expect_block.rb

Instance Attribute Summary

Attributes inherited from Block

#node, #type

Instance Method Summary collapse

Methods inherited from Block

#<<, #children, #range, #succession_error_msg, #valid_successor?

Constructor Details

#initialize(node) ⇒ ExpectBlock

Returns a new instance of ExpectBlock.



9
10
11
# File 'lib/rspock/ast/parser/expect_block.rb', line 9

def initialize(node)
  super(:Expect, node)
end

Instance Method Details

#can_end?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rspock/ast/parser/expect_block.rb', line 17

def can_end?
  true
end

#can_start?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rspock/ast/parser/expect_block.rb', line 13

def can_start?
  true
end

#successorsObject



21
22
23
# File 'lib/rspock/ast/parser/expect_block.rb', line 21

def successors
  @successors ||= [:Cleanup, :Where].freeze
end

#to_rspock_nodeObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/rspock/ast/parser/expect_block.rb', line 25

def to_rspock_node
  statement_parser = StatementParser.new
  spock_children = @children.map { |child| statement_parser.parse(child) }

  if spock_children.any? { |c| c.type == :rspock_raises }
    raise BlockError, "raises() is not supported in Expect blocks @ #{range}. Use a When + Then block instead."
  end

  s(:rspock_expect, *spock_children)
end