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

Renamed #have_same_file_content_like matcher #555

Conversation

xtrasimplicity
Copy link
Member

@xtrasimplicity xtrasimplicity commented Mar 20, 2018

Summary

Removed have_same_file_content_like and a_file_with_same_content_like matchers, and added have_same_file_content_as and a_file_with_same_content_as, as per #485. The previous methods are deprecated in the HEAD of the still branch.

Details

Motivation and Context

To make it easier to understand what the matcher does.

How Has This Been Tested?

Added specs to ensure that the renamed methods are called.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (cleanup of codebase without changing any existing functionality)
  • Update documentation

Checklist:

  • I've added tests for my code
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@xtrasimplicity xtrasimplicity requested a review from mvz March 20, 2018 21:18
@xtrasimplicity xtrasimplicity changed the title Renamed #have_same_file_content_like matcher [WIP] Renamed #have_same_file_content_like matcher Mar 20, 2018
@xtrasimplicity
Copy link
Member Author

xtrasimplicity commented Mar 21, 2018

@mvz It looks like the following code (as of Commit 69e89bd) works perfectly when I run it on cucumber v3.1.0, but fails with the following error on v2.99.0.

# Deprecated matchers
module DeprecatedMatchers
  def have_same_file_content_like(expected)
    RSpec.deprecate('`have_same_file_content_like`', replacement: '`have_same_file_content_as`')

    have_same_file_content_as(expected)
  end

  def a_file_with_same_content_like(expected)
    RSpec.deprecate('`a_file_with_same_content_like`', replacement: '`a_file_with_same_content_as`')

    a_file_with_same_content_as(expected)
  end
end

RSpec.configure do |config|
  config.include DeprecatedMatchers
end
Feature: Existence

  Scenario: Existence                                       # features/non-existence.feature:2
    Given a file named "foo" with:                          # /home/andrew/Development/Projects/aruba/lib/aruba/cucumber/file.rb:23
      """
      hello world
      """
    And a file named "bar" with:                            # /home/andrew/Development/Projects/aruba/lib/aruba/cucumber/file.rb:23
      """
      hello world
      """
    And a file named "nonbar" with:                         # /home/andrew/Development/Projects/aruba/lib/aruba/cucumber/file.rb:23
      """
      hello another world
      """
    Then the file "foo" should be equal to file "bar"       # /home/andrew/Development/Projects/aruba/lib/aruba/cucumber/file.rb:175
      expected foo to respond to `has_same_file_content_like?` (RSpec::Expectations::ExpectationNotMetError)
      /home/andrew/Development/Projects/aruba/lib/aruba/cucumber/file.rb:179:in `/^(?:a|the) file(?: named)? "([^"]*)" should (not )?be equal to file "([^"]*)"/'
      /home/andrew/Development/Projects/aruba/lib/aruba/platforms/local_environment.rb:22:in `call'
      /home/andrew/Development/Projects/aruba/lib/aruba/platforms/unix_platform.rb:78:in `with_environment'
      /home/andrew/Development/Projects/aruba/lib/aruba/api/core.rb:186:in `with_environment'
      /home/andrew/Development/Projects/aruba/lib/aruba/cucumber/hooks.rb:7:in `block in <top (required)>'
      features/non-existence.feature:15:in `Then the file "foo" should be equal to file "bar"'
    And the file "foo" should not be equal to file "nonbar" # /home/andrew/Development/Projects/aruba/lib/aruba/cucumber/file.rb:175

Failing Scenarios:
cucumber features/non-existence.feature:2 # Scenario: Existence

1 scenario (1 failed)
5 steps (1 failed, 1 skipped, 3 passed)
0m0.020s

The tests themselves will require a number of changes before we can upgrade cucumber to 3.1.0. Everything works if I remove the RSpec.configure block and move the methods out of DeprecatedMatchers, but I'm not happy with doing that as it feels a little too hack-y. Any ideas?

@xtrasimplicity
Copy link
Member Author

Scratch that. RSpec::Matchers.send(:include ...) to the rescue! 👍

@xtrasimplicity xtrasimplicity changed the title [WIP] Renamed #have_same_file_content_like matcher Renamed #have_same_file_content_like matcher Mar 24, 2018
@xtrasimplicity
Copy link
Member Author

@mvz Are you happy for me to merge this?

@mvz
Copy link
Contributor

mvz commented Mar 24, 2018

@xtrasimplicity I'll have a look this weekend.

Copy link
Contributor

@mvz mvz left a comment

Choose a reason for hiding this comment

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

Can you rebase this onto still so we deprecate in the 0.14.x series? That way we don't introduce deprecations in the upcoming 1.0 release. On master, it would just be the straight rename.

RSpec::Matchers.alias_matcher :a_file_with_same_content_as, :have_same_file_content_as

# Deprecated matchers
module DeprecatedMatchers
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can safely deprecate these in the 0.14.x series, and drop them entirely for 1.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good to me. I'll rebase this when I get a moment.

.to raise_error RSpec::Expectations::ExpectationNotMetError
end
end
end
end

describe "to have_same_file_content_like" do
it 'calls have_same_file_content_as' do
expect(self).to receive(:have_same_file_content_as)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we test this some other way? Mocking self can lead to all kinds of breakage down the line.

I think you can just test these matchers by using them as intended (though less extensively than the main tests above).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I'll change this over, too. Thanks for reviewing! :)

Copy link
Contributor

Choose a reason for hiding this comment

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

You're welcome!

@mvz
Copy link
Contributor

mvz commented Mar 24, 2018

(I removed the Reviewable badge since Aruba doesn't use it in general.)

@xtrasimplicity
Copy link
Member Author

I've just applied these changes to the still branch, in a new PR:
#557
I'll close this PR off. @mvz Could I please get you to take a look at the other PR?

Thanks!

@olleolleolle
Copy link
Contributor

Thanks for keeping this alive, it’s a change which adds clarity to the testing activity - everyone needs their head clear for that activity.

@mvz
Copy link
Contributor

mvz commented Apr 1, 2018

LGTM!

@xtrasimplicity xtrasimplicity merged commit 53741ea into cucumber:master Apr 1, 2018
@xtrasimplicity xtrasimplicity deleted the Feature/RenameHaveSameFileContentLikeMatcher branch April 1, 2018 08:19
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.

3 participants