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

Move specs out of dummy app v2 #100

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

quorauk
Copy link

@quorauk quorauk commented Aug 11, 2023

Changes

Moves specs out of dummy app so they can be run without changing directory, and as you would expect from a typical ruby project

This makes some changes to the gemfile, I think this is probably ok, but let me know if you want me to move that stuff into the gemspec instead

@PatMiekina has made changes to update the dummy app to rails 7, I think this should allow that to happen without needing to rewrite the tests to the new app

There are additionally some changes to the github workflow that are a little gross to get migrations and gems loaded. Let me know if you have any alternative approaches

Ticket

https://github.com/orgs/pixielabs/projects/4?pane=issue&itemId=31864894

Before submitting have you:

  • Included a link to any relevant ticket
  • Included links to any github issues
  • Prefix the title with the PR type (Feature, Bugfix, Documentation, Chore)

After submitting remember to:

  • Mark the ticket as ready for review
  • Include the PR on the ticket
  • Assign a single reviewer

@quorauk quorauk mentioned this pull request Aug 14, 2023
6 tasks
@quorauk quorauk marked this pull request as ready for review August 21, 2023 14:24
Copy link
Collaborator

@JonathanAndrews JonathanAndrews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I'm not sure about this PR, @quorauk 🤔

This makes some changes to the gemfile, I think this is probably ok, but let me know if you want me to move that stuff into the gemspec instead

I definitely don't want to move the gems into the gemspec, I think that should just contain dependancies that the actual gem needs.

My main thought is that this a pretty big set of changes for allowing a contributor to run the tests from the top level in the app. Was going into the dummy app such a big problem?

I wonder if @defaye would like to take a look. I know he has spoken in the past about disliking how the the tests were in the dummy app.

Gemfile Outdated
Comment on lines 6 to 19
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
gem 'sprockets-rails'
gem 'sqlite3'
gem 'rollbar', '~> 2.11', '>= 2.11.5'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails'
end

group :test do
gem 'capybara'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move all these gems into the test group?
Also could you see if there is a way to include one gem file in another?

bin/setup Outdated
Comment on lines 8 to 12
cd spec/dummy-app
bundle install
./bin/rails db:setup
./bin/rails assets:precompile
cd ../../
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could definitely use a comment.

You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Run `./bin/setup` to install all gems and setup the dummy app.

You can then run the tests from the root of the app using `bundle exec rspec`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it clear that you need to run ./bin/setup before you can run any of the tests?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonably clear to me 🤔

Copy link
Author

@quorauk quorauk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually relatively comfortable with this now

Its probably worth pulling down and trying to run

bundle exec rspec

and check it works for you. It does seem to work pretty well on CI without many ugly hacks

Comment on lines +5 to +7

gem 'turbo-rails'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails couldn't pick this up when its in the test group for some reason

@@ -1,4 +1,4 @@
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __dir__)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows the dummy app to use the gemfile from the gem instead of the one in the dummy app root directory

Comment on lines +1 to +13
require 'active_record'

ActiveRecord::Migration.verbose = false
ActiveRecord::Base.logger = Logger.new(nil)

if Rails.gem_version >= Gem::Version.new('6.0.0')
ActiveRecord::MigrationContext.new(File.expand_path('../dummy/db/migrate', __dir__), ActiveRecord::SchemaMigration).migrate
elsif Rails.gem_version >= Gem::Version.new('5.2.0')
ActiveRecord::MigrationContext.new(File.expand_path('../dummy/db/migrate', __dir__)).migrate
end

DatabaseCleaner[:active_record].strategy = :transaction
ORMInvalidRecordException = ActiveRecord::RecordInvalid
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performs all the database setup and teardown for running tests.

Removes the need to do cd spec/dummy-app; ./bin/rails db:setup on first run

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

Successfully merging this pull request may close these issues.

None yet

3 participants