Class: Opal::Rubyspec::FiltersRewriter
Constant Summary
collapse
- RUBYSPEC_DSL =
%i[describe it context].freeze
Opal::Rewriters::Base::DUMMY_LOCATION
Instance Attribute Summary
#current_node
Class Method Summary
collapse
Instance Method Summary
collapse
#append_to_body, #begin_with_stmts, #dynamic!, #error, #on_top, #prepend_to_body, #process, s, #s, #stmts_of
Constructor Details
Returns a new instance of FiltersRewriter.
29
30
31
|
# File 'lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 29
def initialize
@specs_stack = []
end
|
Class Method Details
.clear_filters! ⇒ Object
24
25
26
|
# File '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 'lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 13
def filter(spec_name)
filters << spec_name
end
|
.filtered?(spec_name) ⇒ Boolean
20
21
22
|
# File 'lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 20
def filtered?(spec_name)
filters.include?(spec_name)
end
|
.filters ⇒ Object
9
10
11
|
# File 'lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 9
def filters
@filters ||= []
end
|
Instance Method Details
#current_spec_name ⇒ Object
72
73
74
|
# File 'lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 72
def current_spec_name
@specs_stack.join(' ')
end
|
#fixture(file, *args) ⇒ Object
Adapted from: spec/mspec/lib/mspec/helpers/fixture.rb
77
78
79
80
81
82
|
# File 'lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 77
def fixture(file, *args)
path = File.dirname(file)
path = path[0..-7] if path[-7..-1] == '/shared'
fixtures = path[-9..-1] == '/fixtures' ? '' : 'fixtures'
File.join(path, fixtures, args)
end
|
#on_send(node) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 35
def on_send(node)
_recvr, method_name, *args = *node
if rubyspec_dsl?(method_name)
dynamic!
spec_name, _ = *args.first
begin
@specs_stack.push(spec_name)
if skip?
s(:nil)
else
super
end
ensure
@specs_stack.pop
end
elsif method_name == :fixture
if args.all? { |i| i.type == :str }
as = args.map { |i| i.children.first }
s(:str, fixture(*as))
else
super
end
else
super
end
end
|
#rubyspec_dsl?(method_name) ⇒ Boolean
68
69
70
|
# File 'lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 68
def rubyspec_dsl?(method_name)
RUBYSPEC_DSL.include?(method_name)
end
|
#skip? ⇒ Boolean
64
65
66
|
# File 'lib/opal/rewriters/rubyspec/filters_rewriter.rb', line 64
def skip?
self.class.filtered?(current_spec_name)
end
|