Class: Opal::Rubyspec::FiltersRewriter

Inherits:
Opal::Rewriters::Base show all
Defined in:
opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb

Constant Summary

RUBYSPEC_DSL =
%i[describe it context].freeze

Constants inherited from Opal::Rewriters::Base

Opal::Rewriters::Base::DUMMY_LOCATION

Instance Attribute Summary

Attributes inherited from Opal::Rewriters::Base

#current_node

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Opal::Rewriters::Base

#append_to_body, #begin_with_stmts, #error, #prepend_to_body, #process, #s, s, #stmts_of

Constructor Details

#initializeFiltersRewriter

Returns a new instance of FiltersRewriter



29
30
31
# File 'opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 29

def initialize
  @specs_stack = []
end

Class Method Details

.clear_filters!Object



24
25
26
# File 'opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 24

def clear_filters!
  @filters = []
end

.filter(spec_name) ⇒ Object Also known as: fails, fails_badly



13
14
15
# File 'opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 13

def filter(spec_name)
  filters << spec_name
end

.filtered?(spec_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 20

def filtered?(spec_name)
  filters.include?(spec_name)
end

.filtersObject



9
10
11
# File 'opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 9

def filters
  @filters ||= []
end

Instance Method Details

#current_spec_nameObject



63
64
65
# File 'opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 63

def current_spec_name
  @specs_stack.join(' ')
end

#on_send(node) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 35

def on_send(node)
  _recvr, method_name, *args = *node

  if rubyspec_dsl?(method_name)
    spec_name, _ = *args.first
    begin
      @specs_stack.push(spec_name)
      if skip?
        s(:nil)
      else
        super
      end
    ensure
      @specs_stack.pop
    end
  else
    super
  end
end

#rubyspec_dsl?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 59

def rubyspec_dsl?(method_name)
  RUBYSPEC_DSL.include?(method_name)
end

#skip?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'opal/lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 55

def skip?
  self.class.filtered?(current_spec_name)
end