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

Migrate all specs to the newer expect syntax #1064

Merged
merged 15 commits into from
Apr 8, 2014
Merged

Conversation

myabc
Copy link
Contributor

@myabc myabc commented Mar 31, 2014

Our specs are currently a mix of the older should syntax and the newer expect syntax. I wanted the excuse to give Transpec a try – as you can see, it seems to do a good job. I needed to make very a handful of subsequent fixes.

This relates to https://www.openproject.org/work_packages/4044 – and may assist with the upgrade to RSpec 3.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
This conversion is done by Transpec 1.10.4 with the following command:
    transpec

* 1414 conversions
    from: obj.should
      to: expect(obj).to

* 646 conversions
    from: == expected
      to: eq(expected)

* 376 conversions
    from: obj.stub(:message)
      to: allow(obj).to receive(:message)

* 107 conversions
    from: obj.should_not
      to: expect(obj).not_to

* 70 conversions
    from: obj.should_receive(:message)
      to: expect(obj).to receive(:message)

* 45 conversions
    from: =~ [1, 2]
      to: match_array([1, 2])

* 27 conversions
    from: lambda { }.should
      to: expect { }.to

* 13 conversions
    from: Klass.any_instance.stub(:message)
      to: allow_any_instance_of(Klass).to receive(:message)

* 8 conversions
    from: === expected
      to: be === expected

* 7 conversions
    from: expect { }.not_to raise_error(SpecificErrorClass)
      to: expect { }.not_to raise_error

* 6 conversions
    from: =~ /pattern/
      to: match(/pattern/)

* 2 conversions
    from: obj.should_not_receive(:message)
      to: expect(obj).not_to receive(:message)

* 1 conversion
    from: < expected
      to: be < expected

* 1 conversion
    from: obj.stub!(:message)
      to: allow(obj).to receive(:message)

* 1 conversion
    from: stub('something')
      to: double('something')
Broken in previous commit 26ade602:

RSpec::Mocks.allow_message is a lower-level API method, allowing us
to define a stub outside of an ExampleGroup context.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
Helper fixed in previous commit e31bec17.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
Deprecated negative raise_error expectations were removed by Transpec
in previous commit 26ade602: this example was previously masking an
ArgumentError.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
RSpec should syntax masked an issue with the route_to matcher on a
separate line not being called.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
Signed-off-by: Alex Coles <alex@alexbcoles.com>
RSpec expect syntax no longer supports this operator matcher.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
@myabc
Copy link
Contributor Author

myabc commented Mar 31, 2014

n.b. This PR doesn't cover cukes, but they could be migrated in a similar fashion.

@hschink
Copy link
Contributor

hschink commented Apr 1, 2014

@myabc In eb70332 the route spec uses post instead of get. I hope that fixes the issue.

* remove query params from expectation, since routing specs do not
  test these.

/ HT: @hschink

Signed-off-by: Alex Coles <alex@alexbcoles.com>
The previous bundle update of all dependencies broke execution of unit
tests: I've yet to determine a more specific cause.

This partially reverts commit 6ea4ed8.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
@myabc
Copy link
Contributor Author

myabc commented Apr 1, 2014

Issue appears to be with simplecov:

bundle update
be ruby -v test/functional/mail_handler_controller_test.rb

See PR #1066 for Gemfile fix.

@hschink
Copy link
Contributor

hschink commented Apr 3, 2014

@myabc I'm sorry but this doesn't work with plug-ins.

@myabc
Copy link
Contributor Author

myabc commented Apr 3, 2014

@hschink OK. Sorry for that. I will revert 4774aeb, so this work can be merged. There is a ticket for converting syntax in plugins: https://www.openproject.org/work_packages/5674

This will break specs on installations with plugins. Reverting until
popular plugins are also migrated to the new RSpec syntax
(see new task: https://www.openproject.org/work_packages/5674)

This reverts commit 4774aeb.
actionpack (>= 3.0)
activemodel (>= 3.0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know where this new dependency comes from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hschink it's now a dependency of rspec-rails, but it's been part of our stack since moving to Rails 3, as it's also a required dependency of Rails/Active Record.

See: rspec/rspec-rails@4549965

@@ -46,9 +46,9 @@
describe 'index.xml' do
describe 'with unknown project_type' do
it 'raises ActiveRecord::RecordNotFound errors' do
lambda do
Copy link
Contributor

Choose a reason for hiding this comment

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

👽

     NoMethodError:
       undefined method `original_path_set' for nil:NilClass

Failure only occurs with a full plugin configuration.

See rspec/rspec-rails#860
@hschink
Copy link
Contributor

hschink commented Apr 4, 2014

@myabc it's still failing on internal CI: This time allow_password_changes? is called on nil.

@myabc
Copy link
Contributor Author

myabc commented Apr 4, 2014

@hschink That's good. It means it's now reproducing what I'm seeing locally. I'll take another look.

With an OpenProject config containing private plugins this spec will
fail with the following Error:

    ActionView::Template::Error: undefined method `allow_password_changes?' for nil:NilClass
    ./app/models/user.rb:377:in `change_password_allowed?'

This failure was most likely previously obscured because
`render_views` was not enabled.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
@myabc
Copy link
Contributor Author

myabc commented Apr 4, 2014

@hschink OK fix posted.

Signed-off-by: Alex Coles <alex@alexbcoles.com>

Conflicts:
	spec/models/permitted_params_spec.rb
	spec/models/work_package/work_package_acts_as_journalized_spec.rb
	spec/models/work_package/work_package_planning_spec.rb
This conversion is done by Transpec 1.10.4 with the following command:
    transpec spec/models/permitted_params_spec.rb

* 10 conversions
    from: obj.should
      to: expect(obj).to

* 10 conversions
    from: == expected
      to: eq(expected)

* 1 conversion
    from: obj.should_receive(:message)
      to: expect(obj).to receive(:message)
tessi pushed a commit that referenced this pull request Apr 8, 2014
Migrate all specs to the newer expect syntax
@tessi tessi merged commit f4282fc into dev Apr 8, 2014
@tessi tessi deleted the fix/rspec-expect-syntax branch April 8, 2014 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants