Giter Site home page Giter Site logo

cucumber-rest-api-assistant's People

Contributors

michaelkeeling avatar

Stargazers

 avatar

Watchers

 avatar

cucumber-rest-api-assistant's Issues

Character conversion error with some responses and log writing

Occasionally a response will be returned which has characters that cannot be converted to UTF-8. I've hit this issue frequently when using debugging and depending on the response this tests in examples.feature will throw it.

Scenario: Use shorthand to save response values for reuse
    Given a GET request is sent to 'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'
    And the value of '0' in the response is saved in a key called 'some_identifier'
    And a GET request is sent to 'https://hacker-news.firebaseio.com/v0/item/{some_identifier}.json?print=pretty'
    Then the response is successful
    And the response code is 200

Which will throw the error:

And a GET request is sent to 'https://hacker-news.firebaseio.com/v0/item/{some_identifier}.json?print=pretty' # lib/cucumber-api-assistant/request_steps.rb:144
      "\xE2" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
      features/example.feature:141:in `And a GET request is sent to 'https://hacker-news.firebaseio.com/v0/item/{some_identifier}.json?print=pretty''

There seem to be lots of opinions out there on how to address this so I didn't attempt a quick fix.

The specific line of code throwing this error is in scenario_to_documentation.rb

File.open(output, 'w') { |file|
  file.write(content) #  <<<<< Right here
}

I think this can be fixed by changing the File.open params to wb+

File.open(output, 'wb+') { |file|
  file.write(content)
}

Document generation should be off by default

This is up for discussion. But I think in most cases a user of this gem won't want documentation to be generated on each test run since it adds lots of output to the logs and the terminal.

Post form data from a file path

Some APIs require that extremely large amounts of data be posted. These APIs accept form data as their request. We need a way to post form data from a file. Why load this data from a file? We don't want to put a huge payload in the feature file.

We should create a new step that allows for this to happen.


Not sure if you saw this in the steps file for FE API but I did something like this for json formatted files

Given(/^the request body is set from the file '(.+)'$/) do |path|
  file_stuff = File.read(path)
  my_output = JSON.parse(file_stuff)

  #DEBUG: Leaving the below statement for now in case there are problems again
  #with the sub step.
  #@request_body = my_output.to_json

  step "the json request body is #{my_output.to_json}"
end

It's not for form data but it's probably something close to this.

URIs with spaces fail

URIs should be properly encoded. If a value with a space is passed in via a template (or used directly) then we attempt to use it as is and Excon throws an exception. This can give a false negative on a test, or at least makes it not obvious that the failure happened as a result of a bad step function vs. the subject under test.

Consider distinguishing "contains" from "equals" in step definitions

The request_steps.rb:190 file defines a step for checking a JSON field's value: "the <name> field in the response contains <value>". The code checks for equality, but "contains" is usually used for a substring comparison.

Both seem useful; maybe the existing "contains" step could be changed to do a containment check, while a new step using the word "equals" would do the current equality check.

Allow the base url to be set by and environment variable

I'd like to be able to use simple syntax when referring to an endpoint (or and enpoint_template) which expects the base_url to be set. The only way I know to do this is through an environment variable but maybe there is another way.

When(/^a (GET|POST|PATCH|PUT|DELETE) request is sent to the endpoint '(.+)'$/) do |verb, endpoint|  
  base_url = ENV['BASE_URL']  
  step "a #{verb} request is sent to '#{base_url}#{endpoint}'"  
end

"the '(.+)' field in the response has a value" method crashes if the value is float

cucumber-api-assistant/request_steps.rb has a method:

Then /^the '(.+)' field in the response has a value$/ do |field|
expect(@response.body).not_to be_empty

value = CucumberApiAssistant::Helpers.fetch_from_JSON_with_shorthand(field, @response.body)
expect(value.size).to be > 0
end

For a field with float value, like:

"percent_used": 8.96

the method crashes with error

undefined method `size' for 10.97:Float (NoMethodError)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.