thoughtbot / appraisal

A Ruby library for testing your library against different versions of dependencies.
https://thoughtbot.com
MIT License
1.25k stars 107 forks source link

byebug not available unless explicitly required? #156

Closed jasonfb closed 3 years ago

jasonfb commented 5 years ago

Question:

I have a basic spec and am simply trying to debug it with byebug

spec/setup_spec

require 'spec_helper'

describe XYZObject do
  it 'should allow me to set it up' do
    byebug
  end
end

Gemfile

source "https://rubygems.org"

gem "appraisal"
gem "rdoc"
gem "rails-controller-testing"

group :test, :development do
  gem 'byebug', require: true
  gem 'rspec-rails'
end

platforms :ruby do

end

Appraisals file

appraise "rails-5-0" do
  gem "rails", "5.0.7.2"
end

appraise "rails-5-1" do
  gem "rails", "5.1.7"
end

appraise "rails-5-2" do
  gem "rails", "5.2.3"
end

when I run appraisal rails-5-0 rake spec I get

XYZObject
  should allow me to set it up (FAILED - 1)

Failures:

  1) XYZObject should allow me to set it up
     Failure/Error: byebug

     NameError:
       undefined local variable or method `byebug' for #<RSpec::ExampleGroups::XYZObject:0x00007fdfac1644a8>
     # ./spec/settings_spec.rb:7:in `block (2 levels) in <top (required)>'

however, if I simply throw a require 'byebug' at the top of settings_spec.rb then it appears to drop into byebug correctly.

is that the expected behavior? the reason I'm asking is because I had thought the gems listed in Gemfile should be available during the appraisal run. Note that I tried this with my Gemfile as both gem 'byebug' and also gem 'byebug', require: true

I should note that I am testing a GEM that has a .gemspec file at its root, as well as a Gemfile and also an Appraisals file

martinstreicher commented 4 years ago

My experience suggests that yes, you need to require it.

jasonfb commented 4 years ago

normally it should be loaded if require: true is in the Gemfile but it seems like this effect is somehow caused by Appraisal

nickcharlton commented 4 years ago

Huh, interesting! Do you have an example project I could look at?

jasonfb commented 4 years ago

you can take a look at the gem I was developing, using Appraisal to test the gem code:

https://github.com/jasonfb/universal_track_manager

jasonfb commented 4 years ago

scroll to the bottom of the readme page and look for "The Internal Specs" for the quick setup needed to run Appraisal on this particular project.

nickcharlton commented 4 years ago

Hmm, I don't seem to be able to replicate this. Running:

bundle exec rspec spec/lib/universal_track_manager/models/visit_spec.rb
bundle exec appraisal rails-5-1 rspec spec/lib/universal_track_manager/models/visit_spec.rb

with byebug on line 30 drops me into a shell with both calls. Did you change anything since you opened this issue originally?