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

Cassette failing when feeding in Datetime object #655

Open
quintrino opened this issue Jul 26, 2017 · 2 comments
Open

Cassette failing when feeding in Datetime object #655

quintrino opened this issue Jul 26, 2017 · 2 comments

Comments

@quintrino
Copy link

I've taken over a Ruby project that uses VCR for for testing and it seems to work for all tests except those where it is being fed a Datetime object.

Here is the code that's included in the test (I commented out the VCR cassette to test direct connections)

test 'should collect the lately updated products' do
# VCR.use_cassette("fetch_all_updated_products_from_shopify_store") do
updateTime = DateTime.now-1
total_count = Shopify::SpProduct.product_count({updated_at_min: updateTime})
products = Shopify::SpProduct.collect_products(total_count, {updated_at_min: updateTime})
assert_equal total_count, products.count
# end
end

My VCR Config is as follows

VCR.configure do |config|
config.cassette_library_dir = 'test/vcr_cassetes'
config.hook_into :webmock
config.allow_http_connections_when_no_cassette = true # this was added to allow direct connections
end

Deleting the cassette causes it to run fine during its initial recording.

I've commented out the VCR elements and it works perfectly fine, only when using the VCR cassette do I get the following error.

ERROR["test_should_collect_the_lately_updated_products", SpProductTest, 2017-07-26 04:31:36 +1000]
test_should_collect_the_lately_updated_products#SpProductTest (1501007496.68s)
VCR::Errors::UnhandledHTTPRequestError: VCR::Errors::UnhandledHTTPRequestError:

    ================================================================================
    An HTTP request has been made that VCR does not know how to handle:
      GET https://XXXXXXXXX.myshopify.com/admin/products/count.json?published_status=published&updated_at_min=2017-07-25T15:05:36%2B10:00

    VCR is currently using the following cassette:
      - ~/Projects/shopify/test/vcr_cassetes/fetch_all_updated_products_from_shopify_store.yml
        - :record => :once
        - :match_requests_on => [:method, :uri]

    Under the current configuration VCR can not find a suitable HTTP interaction
    to replay and is prevented from recording new requests. There are a few ways
    you can deal with this:

      * If you're surprised VCR is raising this error
        and want insight about how VCR attempted to handle the request,
        you can use the debug_logger configuration option to log more details [1].
      * You can use the :new_episodes record mode to allow VCR to
        record this new request to the existing cassette [2].
      * If you want VCR to ignore this request (and others like it), you can
        set an `ignore_request` callback [3].
      * The current record mode (:once) does not allow new requests to be recorded
        to a previously recorded cassette. You can delete the cassette file and re-run
        your tests to allow the cassette to be recorded with this request [4].
      * The cassette contains 2 HTTP interactions that have not been
        played back. If your request is non-deterministic, you may need to
        change your :match_requests_on cassette option to be more lenient
        or use a custom request matcher to allow it to match [5].

    [1] https://www.relishapp.com/vcr/vcr/v/3-0-3/docs/configuration/debug-logging
    [2] https://www.relishapp.com/vcr/vcr/v/3-0-3/docs/record-modes/new-episodes
    [3] https://www.relishapp.com/vcr/vcr/v/3-0-3/docs/configuration/ignore-request
    [4] https://www.relishapp.com/vcr/vcr/v/3-0-3/docs/record-modes/once
    [5] https://www.relishapp.com/vcr/vcr/v/3-0-3/docs/request-matching
    ================================================================================


        ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/request_handler.rb:97:in `on_unhandled_request'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/library_hooks/webmock.rb:129:in `on_unhandled_request'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/request_handler.rb:24:in `handle'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/library_hooks/webmock.rb:144:in `block in <module:WebMock>'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:28:in `block in register_global_stub'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/request_pattern.rb:36:in `matches?'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:58:in `block in request_stub_for'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:57:in `each'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:57:in `detect'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:57:in `request_stub_for'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:50:in `response_for_request'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/net_http.rb:79:in `request'
        ~/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:1156:in `get'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:131:in `block in request'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:128:in `request'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/shopify_api-4.3.1/lib/shopify_api/connection.rb:15:in `request'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:92:in `block in get'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:228:in `with_auth'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:92:in `get'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/custom_methods.rb:57:in `get'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/shopify_api-4.3.1/lib/shopify_api/countable.rb:4:in `count'
        ~/Projects/shopify/app/resource/shopify/sp_product.rb:10:in `block in product_count'
        ~/Projects/shopify/app/resource/shopify/exception_handler.rb:5:in `handle_sp_credential_error'
        ~/Projects/shopify/app/resource/shopify/sp_product.rb:9:in `product_count'
        ~/Projects/shopify/test/api/shopify/sp_product_test.rb:21:in `block (2 levels) in <class:SpProductTest>'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/util/variable_args_block_caller.rb:9:in `call_block'
        ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr.rb:189:in `use_cassette'
        ~/Projects/shopify/test/api/shopify/sp_product_test.rb:19:in `block in <class:SpProductTest>'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/request_handler.rb:97:in `on_unhandled_request'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/library_hooks/webmock.rb:129:in `on_unhandled_request'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/request_handler.rb:24:in `handle'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/library_hooks/webmock.rb:144:in `block in <module:WebMock>'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:28:in `block in register_global_stub'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/request_pattern.rb:36:in `matches?'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:58:in `block in request_stub_for'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:57:in `each'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:57:in `detect'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:57:in `request_stub_for'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/stub_registry.rb:50:in `response_for_request'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/net_http.rb:79:in `request'
    ~/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:1156:in `get'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:131:in `block in request'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:128:in `request'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/shopify_api-4.3.1/lib/shopify_api/connection.rb:15:in `request'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:92:in `block in get'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:228:in `with_auth'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/connection.rb:92:in `get'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/activeresource-4.1.0/lib/active_resource/custom_methods.rb:57:in `get'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/shopify_api-4.3.1/lib/shopify_api/countable.rb:4:in `count'
    ~/Projects/shopify/app/resource/shopify/sp_product.rb:10:in `block in product_count'
    ~/Projects/shopify/app/resource/shopify/exception_handler.rb:5:in `handle_sp_credential_error'
    ~/Projects/shopify/app/resource/shopify/sp_product.rb:9:in `product_count'
    ~/Projects/shopify/test/api/shopify/sp_product_test.rb:21:in `block (2 levels) in <class:SpProductTest>'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr/util/variable_args_block_caller.rb:9:in `call_block'
    ~/.rvm/gems/ruby-2.3.0@shopify/gems/vcr-3.0.3/lib/vcr.rb:189:in `use_cassette'
    ~/Projects/shopify/test/api/shopify/sp_product_test.rb:19:in `block in <class:SpProductTest>

================================================================================

@mcfiredrill
Copy link
Collaborator

Have you tried deleting the cassette and rerecording it?

@quintrino
Copy link
Author

When I delete the cassette the first time I run it the test works and records the cassette, but then when I run it again (and this time uses the existing cassette rather than doing an actual api call) it fails and produces the same error message.

Thanks for reaching out, I'm happy to try anything else you think might help better solve the problem!

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

2 participants