airborne icon indicating copy to clipboard operation
airborne copied to clipboard

Not working with rails

Open karan-ydv opened this issue 2 years ago • 1 comments

I am trying to use airbone with rails. Airborne expect methods keep failing with undefined method '[]' for nil:NilClass. My test looks like this

require 'rails_helper'

describe "MyTest", type: :request do
  it "returns an error" do
    get "/api/users/1"
    expect_json('error', {message: 'not found'})
  end
end

Backtrace:

/Users/karanyadav/project/vendor/bundle/ruby/2.7.0/gems/airborne-0.0.18/lib/airborne/path_matcher.rb:23:in `block in get_by_path'
/Users/karanyadav/project/vendor/bundle/ruby/2.7.0/gems/airborne-0.0.18/lib/airborne/path_matcher.rb:6:in `each'
/Users/karanyadav/project/vendor/bundle/ruby/2.7.0/gems/airborne-0.0.18/lib/airborne/path_matcher.rb:6:in `each_with_index'
/Users/karanyadav/project/vendor/bundle/ruby/2.7.0/gems/airborne-0.0.18/lib/airborne/path_matcher.rb:6:in `get_by_path'
/Users/karanyadav/project/vendor/bundle/ruby/2.7.0/gems/airborne-0.0.18/lib/airborne/request_expectations.rb:58:in `call_with_path'
/Users/karanyadav/project/vendor/bundle/ruby/2.7.0/gems/airborne-0.0.18/lib/airborne/request_expectations.rb:15:in `expect_json'
/Users/karanyadav/project/spec/requests/users_spec.rb:106:in `block (4 levels) in <top (required)>'

rails_helper.rb

require 'spec_helper'
require 'support/factory_bot'
require 'rspec/rails'

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
abort("The Rails environment is running in production mode!") if Rails.env.production?

begin
  ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
  puts e.to_s.strip
  exit 1
end

RSpec.configure do |config|  
  config.use_transactional_fixtures = true
  config.infer_spec_type_from_file_location!  
  config.filter_rails_from_backtrace!  
end

spec_helper.rb

require 'support/factory_bot'
require 'simplecov'

SimpleCov.start

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.shared_context_metadata_behavior = :apply_to_host_groups
  config.include FactoryBot::Syntax::Methods
end

I checked the gem source, it seems that Airbone get method was not called. I tried including airborne in my rails_helper.rb and spec_helper.rb, even replaced RSpec with Airborne everywhere, but it didn't work. How do I get it to run?

karan-ydv avatar May 15 '23 06:05 karan-ydv

Hi there! I have the same error on the same environment, looks like airborne can't transform response.body to json_body object

Solved by using that Gemfile config:

gem 'airborne', github: 'brooklynDev/airborne'

RooTooZ avatar Jun 29 '23 17:06 RooTooZ