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

Remove ActiveRecord based settings from generated rails_helper #1150

Merged
merged 8 commits into from
Aug 29, 2014

Conversation

cupakromer
Copy link
Member

Improve support for Rails apps which do not use ActiveRecord. This does not add settings in the generated spec/rails_helper.rb file which are specific to ActiveRecord. This allows new apps to run without modification, instead of raising errors.

To Do

  • Check for ActiveRecord in the rails_helper.rb template
  • Spec out changes to the template
  • Do not attempt to run migrations if the example app does not use ActiveRecord
  • Implement a 2nd set of smoke tests which do not use ActiveRecord

@cupakromer cupakromer force-pushed the remove-fixtures-on-no-ar branch 4 times, most recently from 42b00cd to 04eadc4 Compare August 22, 2014 17:37
run_generator
expect(File.read( file('spec/rails_helper.rb') )).not_to match(/ActiveRecord::Migration\.check_pending!/m)
expect(File.read( file('spec/rails_helper.rb') )).
to match(/^require 'rspec\/rails'$/m)
Copy link
Member

Choose a reason for hiding this comment

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

I generally dislike this style (where the line break is between expect and `to). I generally tend to use a local for the target:

contents = File.read( file('spec/rails_helper.rb') )
expect(contents).to match(/^require 'rspec\/rails'$/m)

...or put the line break at the opening paren on the matcher:

expect(File.read( file('spec/rails_helper.rb') )).to match(
  /^require 'rspec\/rails'$/m
)

That's just subjective personal preference, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, I tend to fluctuate between breaking as I did and using a boxed matcher. It generally just depends on the matcher.

I think in this case using locals will provide a more readable spec.

Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by a "boxed matcher"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Your breaking at the opening paren. To me it looks like the matcher boxes-in the condition:

.to match(
  /^require 'rspec\/rails'$/m
)

@myronmarston
Copy link
Member

This is looking pretty good but I'm not familiar with these parts of rspec-rails (or with recent versions of rails), so someone who knows that stuff better (perhaps @xaviershay?) should probably review as well.

not_to match(/config\.use_transactional_fixtures/m)
end

case ::Rails::VERSION::STRING.to_f
Copy link
Member

Choose a reason for hiding this comment

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

backwards compatibility sucks :(

@xaviershay
Copy link
Member

Have we written down our official support matrix? And have we considered making it smaller? Like, supporting 4.0 going forward doesn't seem that useful. Rails team isn't even supporting it.

To keep semver, that's maybe a pretty good argument for decoupling rspec-rails version numbers from rspec-core. (Or maybe matching them to rails major/minor!?)

@xaviershay
Copy link
Member

LGTM though

@myronmarston
Copy link
Member

Have we written down our official support matrix?

Officially, it's Rails 3+, against whatever versions of ruby those versions of rails support. You can see the travis build matrix from a recent build:

https://travis-ci.org/rspec/rspec-rails/builds/33315313

Our official support is a bit larger than that simply because we support all 3.0.x releases of rails but only test against the latest patch release of each minor version to cut down on travis build times.

And have we considered making it smaller?

We talked a bit about it when planning what RSpec 3 would be. I said I thought it would be OK for us to drop support for Rails 3, but that I thought it would also be nice to keep supporting it if it is not a big maintenance burden. I left the choice up to Andy and at the time he thought the benefit of supporting it is greater than the cost of doing so.

Since we follow SemVer, we can't drop support for any rails versions until rspec-rails 4.x...unless we decide that SemVer only applies to the other RSpec libs and doesn't apply to rspec-rails.

Like, supporting 4.0 going forward doesn't seem that useful. Rails team isn't even supporting it.

Historically, upgrading Rails has not been easy, so even though the rails team isn't supporting it, there are many, many apps out there on Rails 3.0, 3.1, 3.2 and 4.0...and those apps may want to run the latest RSpec. I think that we do the ruby community a great service by keeping rspec-rails compatible with so many versions of rails (provided rails does a decent job of not breaking the extension points we use...), but of course such support takes a lot of effort and I don't to trivialize that.

If we want to consider dropping support for some rails versions I think we should try to do some kind of community survey so that we have some data about what versions of rails people are actually using with RSpec 3, and let that data guide our decisions. Or, instead of a survey, maybe we can ask some of the companies that have access to Gemfiles from many real apps (e.g. newrelic, github, travis) if they can provide us with this data from their datasets. (New Relic, for example, has published stats about this kind of stuff previously).

To keep semver, that's maybe a pretty good argument for decoupling rspec-rails version numbers from rspec-core.

Interesting idea. If we want to drop support for older versions of rails before we're ready for RSpec 4, we should probably do this.

(Or maybe matching them to rails major/minor!?)

I think this would probably be a big PITA, because it means rails release' schedule would dictate ours. We could only make breaking changes when rails releases a major version, and we can only release new features when rails releases a minor version.

@JonRowe
Copy link
Member

JonRowe commented Aug 23, 2014

Probably should have had the versions discussion before RSpec 3 :P

@cupakromer
Copy link
Member Author

Since we follow SemVer, we can't drop support for any rails versions until rspec-rails 4.x...unless we decide that SemVer only applies to the other RSpec libs and doesn't apply to rspec-rails.

I would prefer we keep rspec-rails following SemVer. It can be a bit of a pain at times, but it makes it easy for people to upgrade / update knowing we do this.

if it is not a big maintenance burden

I'm on the fence here. For the most part no, it has not been. However, there are some issues, such as #1025, where this actually was an extreme pain.

many, many apps out there on Rails 3.0, 3.1, 3.2 and 4.0...and those apps may want to run the latest RSpec. I think that we do the ruby community a great service by keeping rspec-rails compatible with so many versions of rails

I agree with this for the most part. I think with there having been such a long life of RSpec 2.x that this was / is a great benefit. Moving forward, I'm going to have to think a lot about this for 4.x.

maybe we can ask some of the companies that have access to Gemfiles from many real apps (e.g. newrelic, github, travis) if they can provide us with this data from their datasets

I would be very interested in seeing some data.

To keep semver, that's maybe a pretty good argument for decoupling rspec-rails version numbers from rspec-core.

Interesting idea. If we want to drop support for older versions of rails before we're ready for RSpec 4, we should probably do this.

I'm not sure how I feel about this. rspec-rails is in a very interesting position being so tightly coupled with two major libs. I don't think changing things now that we've release 3.x is a good idea, but I'm open to ideas for 4.x. This is something else I'll have to think a bit about.

@myronmarston
Copy link
Member

I would be very interested in seeing some data.

Let me know if you decide to pursue getting that kind of data and want some help from me in doing so.

@JonRowe
Copy link
Member

JonRowe commented Aug 25, 2014

I really don't want us to abandon semver, I'd rather we decouple rspec-rails from rspec than do that. Just my 2¢.

Since we are binstubbing things in general, it's a good idea to actually
try them out when using the generators in the example apps.
More people are not using ActiveRecord these days. The generators should
not include any configs related to `ActiveRecord` when it is not
available. This allows rspec configurations to work properly out-of-the-
box for these other apps.
Creates a 2nd set of generator and smoke tasks which target an example
app which does not use ActiveRecord. In order to accomplish this, a
custom in-memory model is used which supports enough of the AR protocol
to allow default specs to pass.

Use a custom "in-memory" model as the ORM replacement. This is a simple
stand-in allowing us to continue to use all of the other Rails
generators. It also prevents us from needing to pull in another ORM gem
such as such as Mongoid, DataMapper, ROM, etc.

The custom "model" is necessary as the non-ActiveRecord example app's
specs fail with `NameError`s. This is due to the other Rails' generators
expecting to have a "model" type class available, but Rails is unable to
load it.  Just adding the classes does not work as the generated
controllers, form helpers, rendering process, etc. are so tightly
coupled to the `ActiveModel` API interface that all sorts of things
start failing.
Change the directory name from "templates" to "example_app_generator" to
better describe what this directory holds. It is both custom Rails
templates, as well as, generator files.
To help future proof changes in Rails, toggle on feature checks instead
of the Rails version. Use this in the specs as well.

Simplify the case where `ActiveRecord` is not available, by checking for
all options at onice instead of trying to toggle on a feature or Rails
version.
cupakromer added a commit that referenced this pull request Aug 29, 2014
Remove `ActiveRecord` based settings from generated `rails_helper`
@cupakromer cupakromer merged commit 953750d into master Aug 29, 2014
@cupakromer cupakromer deleted the remove-fixtures-on-no-ar branch August 29, 2014 04:15
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.

4 participants