Skip to content

Commit

Permalink
Handle nested example groups in RSpec.describe without runtime data
Browse files Browse the repository at this point in the history
This fixes #89.
  • Loading branch information
yujinakayama committed Aug 28, 2014
1 parent a3328f6 commit f5e1049
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Development

* Fix a bug where nested example groups in `RSpec.describe` are wrongly converted to non-monkey-patch form when dynamic analysis is skipped. ([#89](https://github.com/yujinakayama/transpec/issues/89))

## v2.3.6

* Fix error `Unresolved dependency found during sorting - parser` on `gem install transpec`.
Expand Down
13 changes: 10 additions & 3 deletions lib/transpec/static_context_inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,19 @@ def scope_type(node)
end
end

def special_block_type(block_node)
def special_block_type(block_node) # rubocop:disable MethodLength, CyclomaticComplexity
send_node = block_node.children.first
receiver_node, method_name, *_ = *send_node

if const_name(receiver_node) == 'RSpec' && method_name == :configure
:rspec_configure
if const_name(receiver_node) == 'RSpec'
case method_name
when :configure
:rspec_configure
when *EXAMPLE_GROUP_METHODS
:example_group
else
nil
end
elsif HOOK_METHODS.include?(method_name)
hook_type(send_node)
elsif receiver_node
Expand Down
8 changes: 8 additions & 0 deletions spec/transpec/static_context_inspector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def some_method(some_arg)
end
end
RSpec.describe 'something' do
in_rspec_describe
end
feature 'Capybara DSL' do
background do
in_background
Expand Down Expand Up @@ -118,6 +122,10 @@ def some_method(some_arg)
'send nil :in_block',
'in normal block in #describe in module',
[:module]
], [
'send nil :in_rspec_describe',
'in RSpec.describe',
[:example_group]
], [
'send nil :in_background',
'in #background block in #feature',
Expand Down
36 changes: 36 additions & 0 deletions spec/transpec/syntax/example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,42 @@ module SomeModule
end
end

context 'when the #describe is in another RSpec.describe' do
include_context 'multiple #describes'

let(:source) do
<<-END
RSpec.describe 'something' do
describe '#some_method' do
end
end
END
end

let(:expected_source) do
<<-END
RSpec.describe 'something' do
describe '#some_method' do
end
end
END
end

context 'without runtime information' do
it 'does nothing' do
rewritten_source.should == source
end
end

context 'with runtime information' do
include_context 'dynamic analysis objects'

it 'does nothing' do
rewritten_source.should == source
end
end
end

context 'when logical-inner #describe is placed outside of the outer #describe in source' do
include_context 'multiple #describes'

Expand Down

0 comments on commit f5e1049

Please sign in to comment.