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

undefined method "write" #999

Closed
zsan opened this issue Aug 18, 2022 · 7 comments
Closed

undefined method "write" #999

zsan opened this issue Aug 18, 2022 · 7 comments

Comments

@zsan
Copy link

zsan commented Aug 18, 2022

Hello,

Just FYI, i have this error message when i run rspec

(byebug)  fill_in "Password", with: "12345678"
*** NoMethodError Exception: undefined method `write' for #<StubSocket:0x00007fa21298ab28 @closed=true>

webmock's version 3.18.0

Downgraded to 3.17.1 solve the issue

@bblimke
Copy link
Owner

bblimke commented Aug 18, 2022

@zsan thank you for reporting.

Are you able to provide an example code to reproduce it or show more stacktrace to understand where this write is called?

Would you mind trying the following two commits and see if it works on any of them?

gem 'webmock', github: 'bblimke/webmock', branch: '102dd56'
gem 'webmock', github: 'bblimke/webmock', branch: '2c10bd9'

@rzane any thoughts?

@ingemar
Copy link

ingemar commented Aug 18, 2022

I can confirm that 2c10bd9 is the offending commit.

Installing 102dd56 and our test suite runs just fine!

@bblimke
Copy link
Owner

bblimke commented Aug 18, 2022

I have released 3.18.1 with reverted 2c10bd9

It would be good to get a test or sample code to reproduce the issue or at least a stacktrace from the error.

@MothOnMars
Copy link

@bblimke , I have a test branch that started failing with 3.18.0:
https://github.com/MothOnMars/search-gov/tree/webmock

https://app.circleci.com/pipelines/github/MothOnMars/search-gov/2333/workflows/e2a6416b-7564-4a5b-8ed0-15bb64382a8b

Sample stacktrace:

Traceback (most recent call last):
	14: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/capybara-3.37.1/lib/capybara/selenium/driver.rb:516:in `block in setup_exit_handler'
	13: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/capybara-3.37.1/lib/capybara/selenium/driver.rb:293:in `quit'
	12: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/common/driver.rb:181:in `quit'
	11: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/bridge.rb:186:in `quit'
	10: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/bridge.rb:625:in `execute'
	 9: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
	 8: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/http/default.rb:77:in `request'
	 7: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/http/default.rb:118:in `response_for'
	 6: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/webmock-3.18.0/lib/webmock/http_lib_adapters/net_http.rb:84:in `request'
	 5: from /usr/local/lib/ruby/2.7.0/net/http.rb:1492:in `request'
	 4: from /usr/local/lib/ruby/2.7.0/net/http.rb:1519:in `transport_request'
	 3: from /usr/local/lib/ruby/2.7.0/net/http.rb:1519:in `catch'
	 2: from /usr/local/lib/ruby/2.7.0/net/http.rb:1521:in `block in transport_request'
	 1: from /usr/local/lib/ruby/2.7.0/net/http/generic_request.rb:129:in `exec'
/usr/local/lib/ruby/2.7.0/net/http/generic_request.rb:335:in `write_header': undefined method `write' for #<StubSocket:0x0000564298bf50f0 @closed=true> (NoMethodError)

@zsan
Copy link
Author

zsan commented Aug 18, 2022

@zsan thank you for reporting.

Are you able to provide an example code to reproduce it or show more stacktrace to understand where this write is called?

Hello,

I just put webmock in the Gemfile of my Rails's app, then i put require "webmock/rspec" in spec_helper.rb and i have rspec file like this:

require "rails_helper"

RSpec.feature "LoginMethods", type: :feature, js: true do
  before do
    @google_user = create(:user, login_method: "external", provider: "google_oauth2")
    OmniAuth.config.test_mode = true
  end

  scenario "reject internal login" do
    visit new_user_session_path
    byebug
    fill_in "Email", with: @google_user.email
    fill_in "Password", with: @google_user.password
    click_button "Sign in"
    expect(page).to have_content("This account is for login using Google account.")
  end
end

As you can see i put byebug inside scenario and the error is thrown when i type fill_in "Email", with: @google_user.email within byebug's prompt.

Just FYI, the error is gone when i tried with 3.18.1.

@ingemar
Copy link

ingemar commented Aug 19, 2022

Version 3.18.1 works fine for us! Thank you for your quick work!

@rzane
Copy link
Contributor

rzane commented Aug 23, 2022

Sorry for the trouble everyone. I'll investigate further and try to figure out what went wrong here. The core problem seems to be that StubSocket isn't a very convincing stub of a socket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants