-
Notifications
You must be signed in to change notification settings - Fork 526
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
Rspec3 Update - Spec Syntax, Generators, and Monkey-Patching #692
Conversation
As of rspec-rails 3.2 they generate two files: - spec/spec_helper.rb - spec/rails_helper.rb This allows the user to either do pure ruby unit tests or include the entire rails environment. Draper really only works in a rails application if it has the rails environment. This matches ~> 3.2 and uses the rails_helper instead of spec_helper.
Update gitignore ignore .ruby-gemset and .ruby-version
Fix Spec spec generator because RSpec no longer prefers monkey-patching.
Ignore all .ruby-version, .ruby-gemset, and .rake-tasks files.
Moved dummy/spec to spec, symlinked dummy/spec to spec. This should make the test suite easier to maintain, especially given the changes to RSpec v3. Should also mitigate NameErrors and LoadErrors when running the specs.
Combined spec files were causing a problem with the already-existing rake task and cwd for dummy specs. Moved back to the original setup. Also changed most of the object.stub(method, return_value) to allow(object).to receive(:method).and_return(return_value)
Updated all `should` to `expect` for draper specs, and changed all `object.stub(method)` to `allow(object).to receive(:method)`
…cause RSpec::Rails::Version doesn't exist.
ActiveRecord::Migration.maintain_test_schema! is undefined in Rails 4.0, so I made that method conditional upon ENV['RAILS_VERSION']
Fix Spec spec generator because RSpec no longer prefers monkey-patching. Refactor PR drapergem#675 to be more concise re RSpec Version check, and to use RSpec::Core::Version rather than RSpec::Rails::Version, because the latter does not exist.
Ignore all .ruby-version, .ruby-gemset, and .rake-tasks files. Ignore files generated by rspec_results or coverage reports. Ignore binstubs.
Update gemspec to depend on rspec ~>3.3. Generate standard rails_helper and spec_helper. Make trivial configuration edits to both spec_helpers. Update spec_helper to disable monkey patching, and explicitly use new RSpec 3.0 syntax ActiveRecord::Migration.maintain_test_schema! is undefined in Rails 4.0, so I made that method conditional upon ENV['RAILS_VERSION']
Change specs to use synax `expect(OBJECT).to EXPECTATION` rather that `OBJECT.should`. Changed all `OBJECT.stub(METHOD)` to `allow(OBJECT).to receive(:method)` Change one-liners to use syntax: `it { is_expected.to XXX }` rather than `it { should }`.
Add pry, guard to development group, update Guardfile for new guard-rspec syntax.
Update .travis.yml for more ruby versions
Fix conflicts that weren't real.
Conflicts: spec/draper/collection_decorator_spec.rb spec/draper/decoratable_spec.rb spec/draper/decorated_association_spec.rb spec/draper/decorates_assigned_spec.rb spec/draper/decorator_spec.rb spec/draper/factory_spec.rb spec/draper/finders_spec.rb spec/draper/helper_proxy_spec.rb spec/draper/view_context/build_strategy_spec.rb spec/draper/view_context_spec.rb spec/support/shared_examples/view_helpers.rb
As of rspec-rails 3.3 they generate two files: - spec/spec_helper.rb - spec/rails_helper.rb This allows the user to either do pure ruby unit tests or include the entire rails environment. Draper really only works in a rails application if it has the rails environment. This matches ~> 3.2 and uses the rails_helper instead of spec_helper for the dummy app specs, but the standard spec_helper for the draper specs. Fix Spec spec generator because RSpec no longer prefers monkey-patching. Refactor PR drapergem#675 to be more concise re RSpec Version check, and to use RSpec::Core::Version rather than RSpec::Rails::Version, in case the latter does not exist. Updated all specs to RSpec 3.0 syntax ===================================== Change specs to use synax `expect(OBJECT).to EXPECTATION` rather that `OBJECT.should`. Changed all `OBJECT.stub(METHOD)` to `allow(OBJECT).to receive(:method)` Change one-liners to use syntax: `it { is_expected.to XXX }` rather than `it { should }`. Merge PR drapergem#674 from @mcasper and fix all trivial conflicts (i.e `allow(OBJ).to receive(:message)` vs `allow(OBJ).to receive_messages`) Gitignore ========= Ignore .ruby_version and .ruby_gemset Spec Helper =========== ActiveRecord::Migration.maintain_test_schema! is undefined in Rails 4.0, so I made that method conditional upon ENV['RAILS_VERSION']
Nice job! Congrats. Hope @jcasimir merge this soon as possible. |
While the original spec passed, the generator did not work in practice because RSpec is typically not required in full in the development environment. The generator now explicitly requires RSpec::Version to perform the check.
Any update on either this or my pull request? |
Is there any reason why this wasn't merged? I was going to submit a PR addressing this exact issue. The default spec templates generated by draper are not compatible with proper RSpec 3 configuration. |
@baberthal Sorry we are just now getting back to you. Would you be interested in fixing the conflicts on this? I'd be happy to merge it once you do. |
@codebycliff I'd be happy to. I probably won't be able to get to it until this weekend at the earliest. That work? |
Yes, absolutely. Thanks! |
Although it looks like a lot of these changes were merged with #746. There still stuff to do (e.g. Also, would you mind pulling out the stuff not related to syntax changes (e.g. the addition of guard) into another pull request? It will make it much easier to track changes. |
Are you still interested in fixing these conflicts? |
I'd still support seeing some version of this go through |
@tibbon Are you interested in taking this over? If not, I'll probably close this pull request and try to get to it myself at a later date. |
A lot of what is in this pull request has already been merged. That being said, there are still some things in here that I'd like to get through, so here is what I'm going to do:
Let me know if you have any issue with this. The new pull request can be found here: #853 |
Update to latest RSpec (3.3)
As of rspec-rails 3.3 generates two files:
This allows the user to either do pure ruby unit tests or include the entire
rails environment. Draper really only works in a rails application if it has the
rails environment. This matches ~> 3.3 and uses the rails_helper instead of
spec_helper for the dummy app specs, but the standard spec_helper for
the draper specs, so the entire suite doesn't depend on loading rails.
Fix Spec spec generator because RSpec no longer prefers
monkey-patching. Refactor PR #675 to be more concise re RSpec Version
check, and to use RSpec::Core::Version rather than
RSpec::Rails::Version, in case the latter does not exist.
Updated all specs to RSpec 3.0 syntax
Change specs to use synax
expect(OBJECT).to EXPECTATION
rather thatOBJECT.should
. Changed allOBJECT.stub(METHOD)
toallow(OBJECT).to receive(:method)
Change one-liners to use syntax:
it { is_expected.to XXX }
rather thanit { should }
.Merge PR #674 from @mcasper and fix all trivial conflicts (i.e
allow(OBJ).to receive(:message)
vsallow(OBJ).to receive_messages
)Gitignore
Ignore .ruby_version, .ruby_gemset, any rspec_output, and any generated binstubs.
Spec Helper
ActiveRecord::Migration.maintain_test_schema! is undefined in Rails
4.0, so I made that method conditional upon ENV['RAILS_VERSION'].
Explicitly disable monkey_patching, in addition to some trivial edits related to the RSpec upgrade.
Notes
All the specs pass, although one of the generator specs throws an uninitialized constant RSpec::Support::Differ error. This appears to happen both on travis on on my local machine. I believe it is related to alexrothenberg/ammeter#48, but I can't be sure. Let me know what you guys think and I'll see what I can do to fix it.