Class: Opal::Rubyspec::FiltersRewriter

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

Constant Summary

RUBYSPEC_DSL =
[:describe, :it, :context]

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, #prepend_to_body, #process, #s, s

Constructor Details

#initializeFiltersRewriter

Returns a new instance of FiltersRewriter



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

def initialize
  @specs_stack = []
end

Class Method Details

.clear_filters!Object



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

def clear_filters!
  @filters = []
end

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



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

def filter(spec_name)
  filters << spec_name
end

.filtered?(spec_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.filtersObject



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

def filters
  @filters ||= []
end

Instance Method Details

#current_spec_nameObject



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

def current_spec_name
  @specs_stack.join(" ")
end

#on_send(node) ⇒ Object



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

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)


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

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

#skip?Boolean

Returns:

  • (Boolean)


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

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