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

Not working with rails #167

Open
karan-ydv opened this issue May 15, 2023 · 1 comment
Open

Not working with rails #167

karan-ydv opened this issue May 15, 2023 · 1 comment

Comments

@karan-ydv
Copy link

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?

@RooTooZ
Copy link

RooTooZ commented Jun 29, 2023

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'

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