-
Notifications
You must be signed in to change notification settings - Fork 169
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
Add #unstub method, replace deprecated watir-webdriver with watir #212
Conversation
@bwilczek thanks for the contribution! Looks like the watir upgrade requires us to finally drop support for ruby 1.93. Mind updating the travis config to remove that and add in the more recent ruby versions? |
@bwilczek can you fix up the conflicts here? I just merged a couple smaller PRs in preparation for this breaking change. |
* Add unstub method that acts as opposite of stub * Replace unsupported watir-webdriver with watir * Drop support for Ruby 1.9.3, add newer versions instead
@ronwsmith |
lib/billy/handlers/stub_handler.rb
Outdated
@@ -34,6 +34,11 @@ def stub(url, options = {}) | |||
new_stub | |||
end | |||
|
|||
def unstub(url, options = {:method => :get}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should unstub be given a previously created stub, rather than providing the values to search for one? 🤔
stub = proxy.stub(...)
proxy.unstub(stub)
@bwilczek I wonder if it's easier to conditionally add stubs to the proxy, rather than conditionally remove stubs? I'd be interested to see an example scenario of this new api being applied :) |
@AlanFoster Here's an example :) Let's consider a suite of But, there are some tests (tagged def stub_seach
Billy.proxy.stub("#{SEARCH_HOST}/query/...").and_return(
{some: 'fake objects'}
)
end
def unstub_search
Billy.proxy.unstub("#{SEARCH_HOST}/query/...")
end
RSpec.configure do |c|
c.before(:suite) do
stub_seach
end
c.around(:each, search: true) do |example|
unstub_search
example.run
stub_search
end
end Not sure if the API suggested in one of the previous comments would me more elegant though: def stub_seach
@search_stub = Billy.proxy.stub("#{SEARCH_HOST}/query/...").and_return(
{some: 'fake objects'}
)
end
def unstub_search
Billy.proxy.unstub(@search_stub)
end
RSpec.configure do |c|
c.before(:suite) do
stub_seach
end
c.around(:each, search: true) do |example|
unstub_search
example.run
stub_search
end
end Hope the example is clear. |
@bwilczek Interesting! Won't Puffing Billy's default rspec configuration cause you issues? puffing-billy/lib/billy/init/rspec.rb Lines 9 to 15 in 4468e23
Although - I guess you're not making use of that, if you're referencing |
@AlanFoster And regarding the API: stub = proxy.stub(...)
proxy.unstub(stub) the more I think about it the more I like this approach, I'll test it and implement it if practical. |
@bwilczek For that scenario what are your thoughts on something like: require 'billy/capybara/rspec'
def stub_seach
Billy.proxy.stub("#{SEARCH_HOST}/query/...").and_return(...)
end
RSpec.configure do |config|
config.before(:each, type: :feature) do |example|
stub_search unless example.metadata.key? :with_real_search_functionality
end
end That would give you the functionality you're after at the minute I think 🤔 |
@AlanFoster Your example would work as long as all stubs are reset after each scenario. Given that we use BTW: I've updated the |
@bwilczek @AlanFoster I haven't been following your back and forth closely. Is this PR ready for review, or are you still working through some ideas? |
@ronwsmith It is done from my perspective, so as long as @AlanFoster is OK with the changes the PR is ready for review/merge. |
Released with 1.0.0 |
gem.add_runtime_dependency 'eventmachine', '1.2.0.1' | ||
gem.add_development_dependency 'watir', '~> 6.10.0' | ||
gem.add_runtime_dependency 'addressable', '~> 2.5' | ||
gem.add_runtime_dependency 'eventmachine', '~> 1.0.4' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ronwsmith / @bwilczek Was this version change intentional? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe watir
required it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I believe once I changed watir-webdriver
to watir
I had to change versions of certain other gems - it wouldn't work otherwise. But I don't remember the exact details now.
In some test cases, it is required to dynamically decide which requests should be stubbed, and which not. Using
proxy.reset
is not the best way to it since it provides no control over which stubs are to be removed.This PR adds a new method:
proxy.unstub
, which acts as a reverse toproxy.stub
, and removes only a single stub.See
spec/lib/billy/handlers/stub_handler_spec.rb:66
for examples.Additionally, this PR removes dependency
watir-webdriver
. That gem was outdated, deprecated and in fact already has already been removed from GitHub. It is now a part ofwatir
gem, and this one has been added instead.watir-webdriver
was throwing a ton of warnings (Fixnum) and an exception on justrequire 'watir-webdriver'
making work on this change impossible.