bploetz / versionist

A plugin for versioning Rails based RESTful APIs.
MIT License
972 stars 51 forks source link

Update Generator for Rspec 3 - spec_helper vs rails_helper #70

Closed Rio517 closed 9 years ago

Rio517 commented 9 years ago

Rspec 3 generally replaces requiring spec_helper.rb w/ rails_helper.rb see - more here. The current versionist generator adds require 'spec_helper', which gives a confusing error that was highlighted in https://github.com/bploetz/versionist/issues/66, but was slightly misattributed.

To reproduce the error run the following:

rails new testapp -T
cd testapp
#add rspec-rails to :development and :test groups in your Gemfile
bundle install
rails g rspec:install
rails generate versionist:new_api_version v1 V1 --path=value:v1 --default
rails generate versionist:new_controller foos V1
rspec

Since require 'spec_helper' in rspec 3 no longer loads rails, you'll get an error message along the lines of:

testapp2/spec/controllers/version1/base_controller_spec.rb:3:in `<top (required)>': uninitialized constant V1 (NameError)

A solution might be to check the rspec version, use spec helper for 2.x and rails_helper for 3.x.

If no one beats me to it, I'll submit a pull request in several weeks. Just wanted to open the issue in case it trips anyone else up.

bploetz commented 9 years ago

Thanks for digging into this @Rio517. I'll see how easy it is to fix this so it works with rspec 2.x as well as 3.x.

bploetz commented 9 years ago

@Rio517 I've pushed up a fix for this and verified it locally. Care to take it for a spin to see if it works for you too? In your Gemfile:

gem 'versionist', :git => 'https://github.com/bploetz/versionist.git', :branch => 'fix/issue70'

Then bundle install.

Rio517 commented 9 years ago

Works for me! :)

bploetz commented 9 years ago

Cool thanks. I'll clean up the duplication you mentioned before merging to master and releasing a fix.

bploetz commented 9 years ago

versionist 1.4.1 has been released with this fix. Thanks.