calabash / calabash-ios

Calabash for iOS
Other
1.81k stars 369 forks source link

Webmock compatibility #1382

Open zedtux opened 6 years ago

zedtux commented 6 years ago

I added the webmock gem to my Gemfile, I ran bundle and finally created the features/support/webmock.rb file with the following:

require 'webmock/cucumber'

Running the tests using $(which bundle) exec cucumber -p ios failed with the following :

      Real HTTP connections are disabled. Unregistered request: POST http://127.0.0.1:37265/exit with body '{"post_resign_active_delay":0.4,"post_will_terminate_delay":0.4,"exit_code":0}' with headers {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'Date'=>'Fri, 08 Jun 2018 12:55:16 GMT', 'User-Agent'=>'HTTPClient/1.0 (2.8.3, ruby 2.4.1 (2017-03-22))'}

      You can stub this request with the following snippet:

      stub_request(:post, "http://127.0.0.1:37265/exit").
        with(
          body: {"{\"post_resign_active_delay\":0.4,\"post_will_terminate_delay\":0.4,\"exit_code\":0}"=>nil},
          headers: {
          'Accept'=>'*/*',
          'Content-Type'=>'application/x-www-form-urlencoded',
          'Date'=>'Fri, 08 Jun 2018 12:55:16 GMT',
          'User-Agent'=>'HTTPClient/1.0 (2.8.3, ruby 2.4.1 (2017-03-22))'
          }).
        to_return(status: 200, body: "", headers: {})

      ============================================================ (WebMock::NetConnectNotAllowedError)
      ./features/support/ios/01_launch.rb:41:in `After'

Nice ! 😎 it's working ! Let's allow localhost !

I updated the features/support/webmock.rb file as the following :

require 'webmock/cucumber'

WebMock.disable_net_connect!(allow_localhost: true)

But now when I run again the tests, it is failing with :

Can't convert String into Hash. (TypeError)
./features/support/ios/01_launch.rb:28:in `Before'

It would mean Calabash isn't compatible with WebMock 😢. Anything you know about Webmock and Calabash together?