-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
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>
n.b. This PR doesn't cover cukes, but they could be migrated in a similar fashion. |
* 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>
Issue appears to be with simplecov:
See PR #1066 for Gemfile fix. |
@myabc I'm sorry but this doesn't work with plug-ins. |
@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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@@ -46,9 +46,9 @@ | |||
describe 'index.xml' do | |||
describe 'with unknown project_type' do | |||
it 'raises ActiveRecord::RecordNotFound errors' do | |||
lambda do |
There was a problem hiding this comment.
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
@myabc it's still failing on internal CI: This time |
@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>
@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)
Migrate all specs to the newer expect syntax
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.