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

Rspec3 Updates: Spec Syntax, Generators, and Monkey-Patching (continued) #853

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

Conversation

codebycliff
Copy link
Collaborator

Description

This branch continues the work started in #692. My plan is to fix the conflicts and extract out / revert any unrelated changes.

Testing

Run the test suite.

To-Dos

  • tests

References

mcasper and others added 30 commits May 21, 2015 09:53
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)`
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 #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
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
Kurtis Rainbolt-Greene and others added 3 commits August 27, 2015 14:36
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 #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 #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']
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.
# Conflicts:
#	.travis.yml
#	Gemfile
#	Guardfile
#	draper.gemspec
#	lib/generators/rspec/templates/decorator_spec.rb
#	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/view_context/build_strategy_spec.rb
#	spec/draper/view_context_spec.rb
#	spec/dummy/fast_spec/post_decorator_spec.rb
#	spec/dummy/spec/models/post_spec.rb
#	spec/generators/controller/controller_generator_spec.rb
#	spec/generators/decorator/decorator_generator_spec.rb
#	spec/support/shared_examples/view_helpers.rb
require 'rails_helper'
<% require 'rspec/version' %>
<% if RSpec::Version::STRING.match(/\A3\.[^10]/) %>
require 'rails_helper'
Copy link
Contributor

@jrochkind jrochkind May 30, 2019

Choose a reason for hiding this comment

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

What rspec versions are you trying to test for here with 3 not followed by a 1 or a 0? Are you trying to do rspec version greater than 3.2? That should prob be doc'd in comment, but also, that regexp will fail if rspec gets to 3.10, which it's not far from.

You may be able to use this instead?

if Gem::Version.new(RSpec::Version::STRING) >= Gem::Version.new("3.2")

Which is self-evident enough not to require a comment doc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, the code you have provided is a lot less brittle. This work was originally done by someone else, I just fixed the conflicts and re-opened the pull request. I can only assume they were trying to achieve what you stated above. I haven't had a lot of time lately to work on this. If you are interested in cleaning this up and getting it pushed through, you are more than welcome to take it over.

Copy link
Contributor

@jrochkind jrochkind May 31, 2019

Choose a reason for hiding this comment

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

Hmm, I think the highest priority is actually improving the template for the decorator specs that Draper generates -- this file we're commenting on now.

The rest of the PR seems to be about changing Draper's own specs -- but if Draper's specs currently pass, that doesn't seem to be as much of a priority, as it doesn't really effect the developer users of Draper, like the Draper generator for specs in your own app does.

So if I can find the time, I might open another PR just focusing on that? It sounds like you are a Draper committer/maintainer, so I have some sense that if I can find time to do that, it'll have some chance of being reviewed/merged and my work won't be in vain? :) Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that makes perfect sense. I'd love to see that get improved. And yes, I will be able to review and merge. Sometimes I'm slower to review that I'd personally like, so if that becomes the case, just bug me. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants