Skip to content

Commit

Permalink
Avoid confusing Excon.stub with RSpec's #stub
Browse files Browse the repository at this point in the history
Related to #4.
  • Loading branch information
yujinakayama committed Oct 2, 2013
1 parent 3a42749 commit beef16d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 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 @@

## Master

* Avoid confusing `Excon.stub` with RSpec's `stub` ([#4](https://github.com/yujinakayama/transpec/issues/4))

## v0.1.2

* Continue processing files even if a file has invalid syntax
Expand Down
7 changes: 5 additions & 2 deletions lib/transpec/syntax/method_stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class Syntax
class MethodStub < Syntax
include AbleToAllowNoMessage, AbleToTargetAnyInstance, Util

RECEIVER_CLASS_WHITELIST = ['Typhoeus']
CLASSES_DEFINING_OWN_STUB_METHOD = [
'Typhoeus', # https://github.com/typhoeus/typhoeus/blob/6a59c62/lib/typhoeus.rb#L66-L85
'Excon' # https://github.com/geemus/excon/blob/6af4f9c/lib/excon.rb#L143-L178
]

def allowize!
# There's no way of unstubbing in #allow syntax.
Expand Down Expand Up @@ -54,7 +57,7 @@ def replace_deprecated_method!
def self.target_receiver_node?(node)
return false if node.nil?
const_name = Util.const_name(node)
!RECEIVER_CLASS_WHITELIST.include?(const_name)
!CLASSES_DEFINING_OWN_STUB_METHOD.include?(const_name)
end

def self.target_method_names
Expand Down
14 changes: 14 additions & 0 deletions spec/transpec/syntax/method_stub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ class Syntax
MethodStub.target_node?(send_node).should be_false
end
end

context 'when #stub node with Excon receiver is passed' do
let(:source) do
<<-END
it "is not RSpec's #stub" do
::Excon.stub({}, {:body => 'body', :status => 200})
end
END
end

it 'returns false' do
MethodStub.target_node?(send_node).should be_false
end
end
end

describe '#method_name' do
Expand Down

0 comments on commit beef16d

Please sign in to comment.