Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore extra layers of test contexts #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions example/example_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,33 @@ def pig_latin
end
end

#
#
# Specs
#
#
describe String do
describe '#pig_latin' do
it "should be a pig!" do
"hello".pig_latin.should == "ellohay"
expect("hello".pig_latin).to eq("ellohay")
end

it "should fail to be a pig!" do
"hello".pig_latin.should == "hello"
expect("hello".pig_latin).not_to eq("hello")
end
end
end

describe 'Some context' do
describe '#pig_latin' do
it 'should still be a pig!' do
expect("food".pig_latin).to eq('oodfay')
end
end
end

describe '#pig_latin' do
context 'Some other context' do
it 'should still be a pig in some other context!' do
expect("avocado".pig_latin).to eq('vocadoaay')
end
end
end
end
12 changes: 8 additions & 4 deletions lib/yard-rspec/handler.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
class RSpecDescribeHandler < YARD::Handlers::Ruby::Base
handles method_call(:describe)

handles method_call(:context)

def process
objname = statement.parameters.first.jump(:string_content).source

if statement.parameters[1]
src = statement.parameters[1].jump(:string_content).source
objname += (src[0] == "#" ? "" : "::") + src
end
obj = {:spec => owner ? (owner[:spec] || "") : ""}
obj[:spec] += objname
if statement.parameters.first.jump(:var_ref).type == :var_ref || objname.start_with?("#")
obj[:spec] += objname
end
parse_block(statement.last.last, owner: obj)
rescue YARD::Handlers::NamespaceMissingError
end
end

class RSpecItHandler < YARD::Handlers::Ruby::Base
handles method_call(:it)

def process
return if owner.nil?
obj = P(owner[:spec])
return if obj.is_a?(Proxy)

(obj[:specifications] ||= []) << {
name: statement.parameters.first.jump(:string_content).source,
file: statement.file,
Expand Down