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

Can no longer load acts_as_list in isolation if Rails is installed #145

Closed
botandrose opened this issue Jan 12, 2015 · 5 comments · Fixed by #146
Closed

Can no longer load acts_as_list in isolation if Rails is installed #145

botandrose opened this issue Jan 12, 2015 · 5 comments · Fixed by #146

Comments

@botandrose
Copy link
Contributor

Hello, thanks for maintaining acts_as_list!

I like to unit test my models in isolation from rails, but this is no longer possible if the model depends on acts_as_list, since require 'acts_as_list' now requires rails, as of #114 . Simplest solution would be to revert the PR, but it'd be nice to get the best of both worlds. Could we replace require 'rails' with a test for defined?(Rails), or something similar? \cc @amatsuda

@eagletmt
Copy link
Collaborator

You mean,

  • you have rails in your Gemfile (i.e., you can do require 'rails' successfully),
  • but you won't do require 'rails' while unit-testing models.

right?

@botandrose
Copy link
Contributor Author

Correct. The app is a Rails app, but I unit test the models in isolation, only loading direct dependencies like ActiveRecord and acts_as_list. This gives me sub-second responses from my unit tests, and design feedback from the tests about # of dependencies, etc.

@amatsuda
Copy link
Contributor

@botandrose Sorry for slowing down your tests, but I'm curious, how would you execute your Rails app tests without bundling rails?
Don't you bundle exec when you run them?
Can the test results be reliable enough where the environment is that much different from the production env?

@botandrose
Copy link
Contributor Author

Hi, @amatsuda! Most of my Rails apps have two separate test suites: a high-level acceptance test suite, and a low-level unit test suite. Both suites are pushed as far as possible in their respective directions, and yield very different benefits.

The acceptance tests are as high-level as possible, so they boot Rails, load all the dependencies, and test the happy path through every feature in a black-box fashion (capybara & poltergeist). These tests drive outside-in feature development, check basic correctness, and ensure everything is wired up together, but provide very little code design feedback (if any), nor do they cover edge cases or sad paths. They are also very slow, in the order of magnitude of minutes.

The unit tests, in contrast, are as low-level as possible, so they test only one object at a time in complete isolation (no booting Rails!), while mocking and stubbing any collaborators. This provides excellent code design feedback and forces one to consider things like SRP, cohesion, interfaces, dependencies, etc etc. TDDing with truly sub-second test suites is a really wonderful thing, also. :)

Does this show where I'm coming from? I know not everyone does this, but it works really well if you take the time to do it. To answer your other question, I do not use bundle exec, but rather a gemset per-project, and binstubs in bin/.

@amatsuda
Copy link
Contributor

@botandrose Thank you for explaining clearly! Although I don't follow your practice, I do understand what you're aiming at. Just made a comment to your PR #146.

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 a pull request may close this issue.

3 participants