brooklyndev / airborne Goto Github PK
View Code? Open in Web Editor NEWRSpec driven API testing framework
License: MIT License
RSpec driven API testing framework
License: MIT License
When I hit this uri
http://voteapi-cloud-test.telescope.tv/moderation/getMessages?topic_id=1000336
and use this expectation
expect_json_keys('?', [:position])
I get this error:
I get the same error for *
Am I still running into a bug, or am I doing something wrong?
Perhaps this was expected behavior but when upgrading from 0.1.15 to 0.1.16, I noticed a change in the expect_json function.
Previously this test worked:
it 'GET comments for a single topic for a datasource = facebook' do
get "/topics/#{topic_slug}/comments?datasource_type=facebook"
expect(response.code).to eq(200)
expect_json('comments.*', {datasource: {type: 'FACEBOOK'}})
end
After the update it required me to define the whole json block object for datasource. i.e.
it 'GET comments for a single topic for a datasource = facebook' do
get "/topics/#{topic_slug}/comments?datasource_type=facebook"
expect(response.code).to eq(200)
expect_json('comments.*', {datasource: {key: 'FB', type: 'FACEBOOK', human: 'Facebook'}})
end
While that certainly makes sense, given the amount of tests we have, is there a function that works equivalently to the the old expect_json? I feel that having the ability to be as strict/loose as you like in the test is pretty useful. Particularly in some more complex examples. Thanks!
The following line throws errors because all the keys in json_body
are symbols and not both symbols and strings: expect_json('@id' => '1234')
When the string is converted to a symbol the function works: expect_json(:@id => '1234')
In my case, it gets weirder looking when variables contain colons: expect_json(:'dc:title' => 'Unicorns')
Is there a reason why the keys in json_body shouldn't be both symbols and strings?
I think I know how to fix this, and can provide a pull request.
How to upload a file using airborne
I'm mounting multiple grape endpoints into rails. I'm able to use config.rack_app
to set the app in each spec file without issue. But I was wondering if I could mass load (maybe in rspec) all the endpoints so they are all routable and available at once? Thanks!
Given the following JSON. How could you validate JSON types for the owner's name. This is an example from your documentation, but the Lamborghini's owner has been removed.
{
"cars":[
{
"make":"Tesla",
"model":"Model S",
"owners":[
{
"name":"Bart Simpson"
}
]
},
{
"make":"Lamborghini",
"model":"Aventador"
}
]
}
The optional() method appears to only support optional hashes. How do we validate optional arrays of hashes?
When using Cucumber in the context of rails-cucumber, you can usually extend the Cucumber 'World' simply by passing the module. e.g.,
World(Capybara::DSL)
It seems like this doesn't work with Airborne though. See my SO post here: http://stackoverflow.com/questions/29257549/how-to-extend-world-in-the-context-of-cucumber-rails
And the workaround below. I don't know enough about the inner workings of Cucumber to say why this might be the case.
There is a syntax error when using jRuby resulting from the use of stabby lamdba's. Tested with jruby 1.7.16 in 1.9 mode, so likely to exist on earlier versions.
One example can be found in request_expectations.rb where
-> (data) { expect(data.size).to eq(expected_size) }
could be replaced with
->(data) { expect(data.size).to eq(expected_size) }
to avoid syntax errors (note the removal of the space after the dash rocket).
I'm a little baffled why there's no exact matcher.
In other words, if my api returns
{"public":"here","secret":"here"}
This happily matches (only matches part, I like it)
expect_json(public:'here')
But I'd expect something like this to exist
expect_json_exact(public:'here')
Maybe its not a secret, maybe its unnecessary data and you are trying to reduce bandwidth used.
Hi.
I am relatively new to Rails and probably doing something very stupid, but:
I use Rails with rspec, my tests have type: :request
. When I call get
, post
, etc. in tests, what is actually called is ActionDispatch::Integration::Runner#get
, not airbornes's get
. Which leads to some unexpected results, like "Accept" being "text/html" by default and format:
arg not working. What am I doing wrong?
I want to test one method when database
is empty, so i want to clear
the database
before my test (only ONE test case).
I know that DatabaseCleaner can clear database each test case. But how about only ONE?
It seems at though there may be a problem with dates.
The following fails:
expect_json_types("*", {id: :integer, name: :string, description: :string, created_at: :date})
If I remove the , created_at: :date
it works perfectly.
Here is the error:
Failure/Error: expect_json_types("*", {id: :integer, name: :string, description: :string, created_at: :date})
NoMethodError:
undefined method `include?' for nil:NilClass
Given the following JSON:
[
{
"id":1310926,
"name":"MERCY TIES, DIVIDER, LIL DOWAGER, RAGANA",
"description":"MERCY TIES(seattle) and DIVIDER(ny) are on tour together. Come to the Hemlock oct 20th to support this glory kid couple and local crushers RAGANA and LIL DOWAGER. \n\nRAGANA Oakland two piece heavy, dark atmosphere.\nhttp://ragana.bandcamp.com/\n\nMERCY TIES chaotic hardcore punk rock from Seattle.\nhttp://mercyties.bandcamp.com/\n\nDIVIDER Dirge. Crush. Heavy. Riffage. From New York\nhttp://www.altpress.com/features/entry/divider_all_barren_album_premiere \n\nLIL DOWAGER Oakland harsh and noise post-something.\nhttp://lildowager.bandcamp.com/",
"start":"2014-10-19T17:00:00.000-07:00",
"end":"2014-10-20T17:00:00.000-07:00",
"created_at":"2014-10-05T23:09:27.487-07:00",
"updated_at":"2014-10-16T22:38:52.096-07:00",
"latitude":37.7874165773392,
"longitude":-122.420076951385,
"address":"1151 Polk St, San Francisco, CA 94109",
"source_url":"https://world.timeout.com/events/mercy-ties-divider-lil-dowager-tba",
"upstream_pic_thumb_url":"https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xpf1/v/t1.0-9/c7.0.50. 50/p50x50/1798194_732430210170553_8908067978434556047_n.jpg?oh=cf33bdbd5803b08babdb88bbc69ae9b8 \u0026oe=54B9C961\u0026__gda__=1422114503_084a38ae5ae947dc1cfdaab5b3d4c0e6",
"upstream_pic_url":"https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xpf1/v/t1.0-9/c15.0.100. 100/p100x100/1798194_732430210170553_8908067978434556047_n.jpg?oh=ddb646d41178d74c8f28f02f36620183 \u0026oe=54EF78C1\u0026__gda__=1424833127_023b884e1845b96fd5e8bfa7f586efc5",
"upstream_pic_big_url":"https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xpf1/v/t1.0-9/c30.0.200. 200/p200x200/1798194_732430210170553_8908067978434556047_n.jpg?oh=0fc3068ef6a1004608ec2d77429cdf21 \u0026oe=54BC9249\u0026__gda__=1421813487_460f538e7b15a558a2a2e263440a4599",
"upstream_pic_small_url":null,
"embedd_video_url":null,
"updates_count":0,
"published":true,
"moderating":false,
"status_id":1,
"price":null,
"repeating":null,
"public":null,
"twitter_url":null,
"facebook_url":null,
"hashtags":null,
"name_billing":null,
"ticket_link":null,
"show_only_as_deal":false,
"rsvp_count":0,
"rsvps_count":0,
"import_event_id":2582,
"parent_id":null,
"search_vector":"'/features/entry/divider_all_barren_album_premiere':63B '1151':74C '20th':22B '94109':80C 'atmospher':42B 'ca':79C 'chaotic':46B 'come':17B 'coupl':28B 'crush':55B 'crusher':31B 'dark':41B 'dirg':54B 'divid':3A,11B,53B 'dowag':5A,35B,65B 'famili':81B 'francisco':78C 'glori':26B 'hardcor':47B 'harsh':67B 'heavi':40B,56B 'hemlock':20B,82B 'kid':27B 'lil':4A,34B,64B 'lildowager.bandcamp.com':73B 'local':30B 'merci':1A,7B,44B 'mercyties.bandcamp. com':52B 'new':59B 'nois':69B 'ny':12B 'oakland':37B,66B 'oct':21B 'piec':39B 'polk':75C 'post':71B 'post-someth':70B 'punk':48B 'ragana':6A,32B,36B 'ragana.bandcamp.com':43B 'riffag':57B 'rock':49B 'san':77C 'seattl':9B,51B 'someth':72B 'st':76C 'support':24B 'tavern':83B 'tie':2A,8B,45B 'togeth':16B 'tour':15B 'two':38B 'www.altpress.com':62B 'www. altpress.com/features/entry/divider_all_barren_album_premiere':61B 'york':60B",
"venue_name":"Hemlock Tavern",
"venue":{
"id":3302147,
"name":"Hemlock Tavern",
"latitude":37.7874165773392,
"longitude":-122.420076951385,
"address":"1131 Polk St, San Francisco, CA, United States, 94109",
"created_at":"2014-10-16T22:38:52.081-07:00",
"updated_at":"2014-10-16T22:38:52.081-07:00",
"user_id":null,
"moderator_id":null,
"fb_graph_id":null,
"city":null,
"state":null,
"country":null,
"street":null,
"zip":null,
"status_id":null,
"venue_type_id":null,
"public":null,
"capacity":null,
"stages":null,
"floors":null,
"rooms":null,
"north_east_latitutde":null,
"north_west_latitutde":null,
"south_east_latitutde":null,
"south_west_latitutde":null,
"north_east_longitude":null,
"north_west_longitude":null,
"south_east_longitude":null,
"south_west_longitude":null,
"facebook_url":null,
"photo":{
"url":null,
"thumb":{
"url":null
},
"ios_profile":{
"url":null
},
"medium":{
"url":null
}
},
"description":null,
"logo":{
"url":null,
"thumb":{
"url":null
},
"ios_profile":{
"url":null
},
"medium":{
"url":null
}
},
"search_vector":"'1131':3C '94109':11C 'ca':8C 'francisco':7C 'hemlock':1A 'polk':4C 'san':6C 'st':5C 'state':10C 'tavern':2A 'unit':9C"
},
"status":"active",
"total_checkins=":0,
"total_attending=":0
}
]
When I hit this uri
http://voteapi-cloud-test.telescope.tv/moderation/getMessages?topic_id=1000336
and use this expectation
expect_json_keys('0', [:position])
I get this error:
As far as I can tell I am calling expect_json_keys exactly like the documentation specifies. What is going wrong?
Hi everyone I tried to test my dummy grape app https://github.com/viy/ab with airborne and got this error
Errno::ECONNREFUSED: Connection refused - connect(2) for nil port 80
./spec/request/api/v1/share_pont_spec.rb:11:in block (3 levels) in <top (required)>' -e:1:in
load'
-e:1:in `
any ideas why this error occurs?
I am using json_spec
currently and just started using this gem.
I like how I can validate the types easily with expect_json_types
.
But I found no API for Array size, which is very common when writing spec for collection endpoints.
(Like expect_json_size
)
I am staying with have_json_size
from json_spec
at the moment.
Hello --
The post is successful, but the only return value I am receiving is 481973
.
Ran the call manually through the API and received only one integer value for response and I am not sure how to quantify that within the testing framework since there is no structure.
Manual Response: (NOTE: the integer is different since they are all unique values)
477877
Test:
it 'should create a new field' do
post "/fields", {shortcut_name: "#{Faker::Lorem.characters(10)}", display_name: "#{Faker::Lorem.characters(5)}", field_type: "text", widget_type: "text", column_order: 0}
end
Gemfile:
faker (1.4.3)
airborne (0.1.11)
json (1.7.6)
Error:
1) GET - Fields should create a new field
Failure/Error: post "/fields", {shortcut_name: "#{Faker::Lorem.characters(10)}", display_name: "#{Faker::Lorem.characters(5)}", field_type: "text", widget_type: "text", column_order: 0}
JSON::ParserError:
757: unexpected token at '481973'
# /Users/dhale/.rvm/gems/ruby-2.1.0/gems/json-1.7.6/lib/json/common.rb:155:in `parse'
# /Users/dhale/.rvm/gems/ruby-2.1.0/gems/json-1.7.6/lib/json/common.rb:155:in `parse'
# /Users/dhale/.rvm/gems/ruby-2.1.0/gems/airborne-0.1.11/lib/airborne/base.rb:82:in `set_response'
# /Users/dhale/.rvm/gems/ruby-2.1.0/gems/airborne-0.1.11/lib/airborne/base.rb:32:in `post'
# ./spec/api_spec.rb:52:in `block (2 levels) in <top (required)>'
Thanks for your assistance!
This is my test:
it "returns expected json" do
delete :destroy, id: @location_1.id
expect_json(nil)
end
This is my code destroy action:
def destroy
location = Location.find(params[:id])
authorize! :crud, Location
location.destroy
head :no_content
end
This is the rspec output:
Failure/Error: expect_json(nil)
Airborne::InvalidJsonError:
Api request returned invalid json
When I inspect the response body:
response.body #=> ""
Please tell me how I should test this scenario give my code ---> head :no_content
Thank you!
Saw it through bundle update
but there is not commit about it here
I understand that this gem is unstable until a v1.x is release, but the latest v0.1.16 introduced some breaking changes (expect_json
is more strict in how it diffs actual and expected responses).
It would be great if this gem would adapt Semantic Versioning and start keeping a changelog.
I could submit i PR with a changelog for the current versions, but it works best when there are tags for each of the released versions.
Hi. Have you guys thought about making the calls more "rspec-style"? At least for typical cases (you know, those 20% that are used 80% of the time).
Like, turn
expect_json '?.category', {name: chosen_category.name}
into
expect(:any).to_have :category, with: {name: chosen_category.name}
I would love to participate in that.
If the API returns an array of objects in JSON, how can we test it using airborne?
An example would be awesome.
Thank you
I'm testing grape api. Early, tests completed without errors. After I move api files from app/api to app/lib/api and to config this line:
config.include RSpec::Rails::RequestExampleGroup, type: :request, file_path: /spec\/lib\/api/
some tests (expect_status, expect_json) fails with error:
Failure/Error: expect_status 201.to_s
JSON::ParserError:
757: unexpected token at 'null'
but expect(response.status).to eq(201) no fail.
User Story:
As a user I'd like airborne to throw an error if object called is not present within the json_body
so that I have better clarity on my malformed test
Test - POST:
it 'should add new members or update existing members in bulk' do
$faker_members = Faker::Internet.safe_email
post '/members', {"members" => [{"email" => "#{$faker_members}"}]}
$post_member_from_members = json_body[:member_id]
puts "#{$post_member_from_members} - Members"
expect_status(200)
end
Test - PUT:
it 'should add a single member to one or more groups' do
put "/members/#{$post_member_from_members}/groups", {}
expect_status(200)
end
json_body
object called in test:
$post_member_from_members = json_body[:member_id]
Actual json_body
:
{
"import_id": 1234
}
Result of puts
:
- Members
Failure on PUT:
1) PUT - Members should add a single member to one or more groups
Failure/Error: expect_status(200)
expected: 200
got: 404
(compared using ==)
# /Users/dhale/.rvm/gems/ruby-2.1.0/gems/airborne-0.1.13/lib/airborne/request_expectations.rb:35:in `expect_status'
# /Users/dhale/.rvm/gems/ruby-2.1.0/gems/airborne-0.1.13/lib/airborne/request_expectations.rb:62:in `call'
# /Users/dhale/.rvm/gems/ruby-2.1.0/gems/airborne-0.1.13/lib/airborne/request_expectations.rb:62:in `block (2 levels) in <module:RequestExpectations>'
# ./spec/api_spec.rb:313:in `block (2 levels) in <top (required)>'
this code:
describe 'zKillboard parsing' do
it 'What is inside of a killmail?' do
get 'https://zkillboard.com/api/solo/kills/characterID/268946627/'
#puts "JSON: #{puts json_body[0]}" # See JSON in code below for referance
end
end
causes the following error:
1) zKillboard parsing What is inside of a killmail?
Failure/Error: get 'https://zkillboard.com/api/solo/kills/characterID/268946627/'
NoMethodError:
undefined method `body' for nil:NilClass
# /Users/frances/.rvm/gems/ruby-2.0.0-p451/gems/airborne-0.0.20/lib/airborne/base.rb:72:in `set_response'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451/gems/airborne-0.0.20/lib/airborne/base.rb:28:in `get'
# ./zKillboardRspec_spec.rb:7:in `block (2 levels) in <top (required)>'
Finished in 1.23 seconds (files took 1.69 seconds to load)
1 example, 1 failure
Am I doing something stupid, or is this broken?
For instances where airborne http requests are used json_body
is set from within the request. However, rails is not using the airborne requests and therefore not setting @json_body
, unless one of the airborne custom matchers are called first.
it 'should set json_body' do
get '/foo'
expect(json_body).to eq('foo')
end
This will throw an invalid JSON exception which is completely wrong.
After some failures i noticed that you don't use params = {} parameter in the GET request as rack-test does.So you have to interpolate it like:
get "/endpoint?foo=#{test}"
But in ruby < 2.2 it gives a bad URI error so i had to use URI.encode
Why is that?
Thanks!
Is there airborne'y way so sign requests with oAuth token?
I found only way to do it directly with RestClient before exec proc:
access_token = MyModule.get_oauth[:token]
RestClient.reset_before_execution_procs
RestClient.add_before_execution_proc do |req, params|
access_token.sign! req
end
get "#{MyModule.base_url}/rest/agent/user"
This chunk could be executed across many examples. Any advices how to make it more DRY?
I want to use Sourcegraph code search and code review with airborne. A project maintainer needs to enable it to set up a webhook so the code is up-to-date there.
Could you please enable airborne on @sourcegraph by going to https://sourcegraph.com/github.com/brooklynDev/airborne and clicking on Settings? (It should only take 15 seconds.)
Thank you!
I am trying to test an API that returns all information as strings, e.g. :moonID=>"0". When I try to assert that moonID is a string, I get the following error:
Expected moonID to be of type string, got Fixnum instead
But, if I try to assert that it is an Int, I get an error saying it is a string.
Expected moonID to be of type int, got String instead
This is the code:
it "Tickle for a single item " do
get 'https://zkillboard.com/api/solo/kills/characterID/268946627/'
puts "zKillboard is: #{json_body[1]}"
expect_json_types('*', {moonID: :string}) # This should pass
expect_json_types('*', {moonID: :int}) # This should fail because you get a string
end
This is the first error message:
Failures:
1) Tickling APIs for fun - Tickle the zKillboard API
Failure/Error: expect_json_types('*', {moonID: :string})
Expected moonID to be of type string, got Fixnum instead
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/request_expectations.rb:110:in `block in expect_json_types_impl'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/request_expectations.rb:98:in `each'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/request_expectations.rb:98:in `expect_json_types_impl'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/request_expectations.rb:10:in `block in expect_json_types'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/request_expectations.rb:61:in `block in call_with_path'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/path_matcher.rb:28:in `block in get_by_path'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/path_matcher.rb:28:in `each'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/path_matcher.rb:28:in `get_by_path'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/request_expectations.rb:60:in `call_with_path'
# /Users/frances/.rvm/gems/ruby-2.0.0-p451@restfulAPI/gems/airborne-0.0.20/lib/airborne/request_expectations.rb:9:in `expect_json_types'
# ./helloWorldRspec_spec.rb:28:in `block (2 levels) in <top (required)>'
Here is the JSON in question:
{:killID=>"22356123", :solarSystemID=>"30001382", :killTime=>"2012-02-17 21:39:00", :moonID=>"0", :victim=>{:shipTypeID=>"594", :damageTaken=>"1999", :factionName=>"", :factionID=>"0", :allianceName=>"RvB - BLUE Republic", :allianceID=>"99000652", :corporationName=>"Blue Republic", :corporationID=>"1741770561", :characterName=>"Commander Reed", :characterID=>"1828062917", :victim=>""}, :attackers=>[{:characterID=>"268946627", :characterName=>"Karbowiak", :corporationID=>"1699307293", :corporationName=>"Red Federation", :allianceID=>"99000645", :allianceName=>"RvB - RED Federation", :factionID=>"0", :factionName=>"", :securityStatus=>"-1.72987128117126", :damageDone=>"1999", :finalBlow=>"1", :weaponTypeID=>"2185", :shipTypeID=>"12023"}], :items=>[{:typeID=>"438", :flag=>"0", :qtyDropped=>"0", :qtyDestroyed=>"1", :singleton=>"0"}, {:typeID=>"3568", :flag=>"0", :qtyDropped=>"0", :qtyDestroyed=>"1", :singleton=>"0"}, {:typeID=>"3162", :flag=>"0", :qtyDropped=>"0", :qtyDestroyed=>"3", :singleton=>"0"}, {:typeID=>"11285", :flag=>"5", :qtyDropped=>"0", :qtyDestroyed=>"5", :singleton=>"0"}, {:typeID=>"11349", :flag=>"0", :qtyDropped=>"1", :qtyDestroyed=>"0", :singleton=>"0"}, {:typeID=>"12614", :flag=>"0", :qtyDropped=>"168", :qtyDestroyed=>"336", :singleton=>"0"}, {:typeID=>"448", :flag=>"0", :qtyDropped=>"0", :qtyDestroyed=>"1", :singleton=>"0"}, {:typeID=>"12614", :flag=>"5", :qtyDropped=>"0", :qtyDestroyed=>"1000", :singleton=>"0"}, {:typeID=>"11285", :flag=>"0", :qtyDropped=>"1", :qtyDestroyed=>"0", :singleton=>"0"}, {:typeID=>"2048", :flag=>"0", :qtyDropped=>"1", :qtyDestroyed=>"0", :singleton=>"0"}], :zkb=>{:totalValue=>"9664154.53", :points=>"8"}}
I am making three requests in a rspec example. The responses are correct but the matchers after second request are failing because they keep comparing using the response of first request.
describe "Sign Out" do
it "should expire the auth token" do
# Sign In
post "/api/v1/sign_in", {"email": @user.email, "password": @user.password}, :format => :json
expect_status(200) #OK
auth_token = response.header['X-Auth-Token']
email = response.header['X-User-Email']
# Sign out
post "/api/v1/sign_out", {}, {'X-User-Email' => email, 'X-Auth-Token' => auth_token, 'Content-Type' =>'application/json'}
body = response.body
expect_status(200) #OK
expect_json("message": "Signed out successfully.")
# Trying with expired token
get "/api/v1/cycle_days", {'X-User-Email' => email, 'X-Auth-Token' => auth_token}, :format => :json
expect_status(401)
end
end
Here is the error.
Failure/Error: expect_json("message": "Signed out successfully.")
expected: "Signed out successfully."
got: "Signed in successfully."
I'd like to check for certain dates and times in JSON output, but I'm running into problems comparing JavaScript Date
s and Ruby DateTime
s.
This is my current hack:
expect_json({
...
createdAt: -> (created_at) { DateTime.parse(created_at) - user.created_at.to_datetime < 1000 * 60 },
...
})
Have any suggestions for improvement? Or would you mind adding in some helper methods for date operations?
Thanks for the useful library!
In 0.1.15 I had no issue with expect_json([])
but now that I upgraded to 0.2.1 it throws an error:
Failure/Error: expect_json([])
NoMethodError:
undefined method `keys' for []:Array
# /ruby-2.2.3/gems/airborne-0.2.1/lib/airborne/request_expectations.rb:83:in `expect_json_impl'
# /ruby-2.2.3/gems/airborne-0.2.1/lib/airborne/request_expectations.rb:19:in `block in expect_json'
# /ruby-2.2.3/gems/airborne-0.2.1/lib/airborne/request_expectations.rb:139:in `call_with_path'
# /ruby-2.2.3/gems/airborne-0.2.1/lib/airborne/request_expectations.rb:18:in `expect_json'
Is this expected?
My API return {"result":"error","content":{"code":"LOGIN_DATA_INCORRECT","parameters":{"loginAttemptsLeft":4}}}
and I want to check that loginAttemptsLeft
was decremented after some actions.
For now when I want to use complex matcher (via Proc
) I need to use symbols as key i.e.:
expect_json(content: -> (n) { expect(n[:parameters][:loginAttemptsLeft]) < 5 })
But it would be awesome to have same complex matchers for dot paths like so:
expect_json('content.parameters.loginAttemptsLeft' -> (attemts_left) { expect(attemts_left) < 5 })
http://brooklyndev.github.io/airborne/ (in bottom) have some code snippet:
Airborne.configure.do |config|
config.base_url = 'http://example.com/api/v1'
config.headers = {'x-auth-token' => 'my_token'}
end
Not work.
Airborne.configure.do |config|
=> Airborne.configure do |config|
For Example
it 'should throw a normal error' do
get '/foo'
expect_json_types(foo: :foo )
end
Will throw
NoMethodError:
undefined method `include?' for nil:NilClass
Hi,
Do you really need ActiveSupport >= 4.0.1 as dependency ?
I have a Rails 3.2 project and I want to use airbone but I can't because of this.
Jules
FYI, rest-client
has a security vulnerability in the versions required by airborne
: http://www.osvdb.org/show/osvdb/117461
It's fixed in 1.7.3: https://github.com/rest-client/rest-client/blob/master/history.md#173
I am trying to login
I tried
post '/user/login', { :email => 'username', :password => 'password' }
Tried
post '/user/login', { :email => 'username', :password => 'password' } , { 'Content-Type' => 'application/x-www-form-urlencoded' }
and get an error message
I can login with postman using the same credentials
I can login with frisby.js
frisby.create('login')
.post(BASE_URL + 'user/login',
{
email: email,
password: password
}
)
.expectStatus(200)
.expectJSON({
status: 0
})
I'm having an issue where json_body is returning nil, but body returns the data I expect. Do you have any insight as to what might cause that?
This line forces the Content-Type to be application/json:
headers = { content_type: :json }.merge(options[:headers] || {})
However there are other kinds of content types, such as application/vnd.api+json
(http://jsonapi.org/), designed specifically to build APIs, that should be allowed.
I think that just checking if the header exists in the options is enough to solve this issue.
Thanks!
Here is my airborne api spec with base_url configuration:
require 'rails_helper'
require 'airborne'
Airborne.configure do |config|
config.rack_app = API
config.base_url = 'http://example.com/api/v1'
end
describe V1::Freewheeler::People do
it "GET /api/v1/people" do
get "/people"
end
end
OUTPUT
Failures:
1) V1::Freewheeler::People GET /api/v1/people
Failure/Error: get "/people"
ActionController::RoutingError:
No route matches [GET] "/people"
If I provide full url then it pass
require 'rails_helper'
require 'airborne'
Airborne.configure do |config|
config.rack_app = API
config.base_url = 'http://example.com/api/v1'
end
describe V1::Freewheeler::People do
it "GET /api/v1/people" do
get "http://example.com/api/v1/people"
end
end
_output:_
Randomized with seed 39703
.
Finished in 0.88466 seconds (files took 16 minutes 29 seconds to load)
1 example, 0 failures
Randomized with seed 39703
What am I missing here?
I can seem to use this method to check for multiple keys, it it possible? Sorry, I'm not super ruby fluent just yet!
tried:
expect_json_keys (:_keys, :embedded)
but get:
syntax error, unexpected ','
Thanks,
Bob
If I get a link that 302s via curb then I'm able to see the Location:
header with the correct 302
status code. Airborne auto follows the redirect and the status code for the original get request is unavailable. Is there a way to toggle follow redirects?
Hello. I want send POST request with form data.
All my requests don't send request with :form
.
Why?
# encoding: utf-8
require 'airborne'
describe '' do
it '' do
post 'http://httpbin.org/post', {}, {params: {foo: 'bar'}}
puts json_body # {:args=>{:foo=>"bar"}, :data=>"{}", :files=>{}, :form=>{}, :headers=>{:Accept=>"*/*; q=0.5, application/xml", :"Accept-Encoding"=>"gzip, deflate", :"Content-Length"=>"2", :"Content-Type"=>"application/json", :Host=>"httpbin.org", :"User-Agent"=>"Ruby"}, :json=>{}, :origin=>"195.151.220.177", :url=>"http://httpbin.org/post?foo=bar"}
post 'http://httpbin.org/post', {foo: 'bar'}
puts json_body # {:args=>{}, :data=>"{\"foo\":\"bar\"}", :files=>{}, :form=>{}, :headers=>{:Accept=>"*/*; q=0.5, application/xml", :"Accept-Encoding"=>"gzip, deflate", :"Content-Length"=>"13", :"Content-Type"=>"application/json", :Host=>"httpbin.org", :"User-Agent"=>"Ruby"}, :json=>{:foo=>"bar"}, :origin=>"195.151.220.177", :url=>"http://httpbin.org/post"}
end
end
Soooooory for my bad english. :(
Or remove it if you are lazy
I am using expect_json_types and expect_json and getting some unexpected results when testing with an empty array.
To illustrate, take the "test_responses/array_with_index.json" file and modify to be an empty array:
{
"cars":[]
}
The following two expectations pass but I think they should be failing.
expect_json('cars.?', {make: 'Toyota'})
expect_json_types('cars.*', {some_key: :integer, name: :string})
Here is the json that is giving me greif
https://gist.github.com/fmorales/5b21b301c5e8ae39118c
I am trying to get to value7 under WhatIsThis. WhatIsThis is an object, and value7 is an array under it. I am trying to get to it with:
expect_json_types('array2..WhatIsThis..array3.0', {value7: :string_or_null})
I get an error that I am getting a hash. I looked in the docs for how I access a hash, but I can't find anything. Help!
I have many context group for my controller spec.
But I always needs to add the get /path
at the very end BUT in before hook
I just tried put the get
in subject
to avoid the repeated call, it works with json_spec
since they implement with custom matcher.
But it doesn't work with this gem, with error complaining about missing json_body
, meaning subject
is not called.
Is there a way to make it call subject
when one of the API methods (e.g. expect_json_types
) is called?
There are scenarios where you may want to make sure that the value is nil.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.