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

Upgrade to RSpec 3 #55

Merged
merged 4 commits into from
Oct 9, 2014
Merged

Upgrade to RSpec 3 #55

merged 4 commits into from
Oct 9, 2014

Conversation

Willianvdv
Copy link
Contributor

So far I did:

  • Upgrade from RSpec 2.99 to 3.1
  • Replaced .should with RSpec's 3 expect syntax

Todo:

example_group is deprecated, therefore https://github.com/Willianvdv/approvals/blob/rspec3/lib/approvals/namers/directory_namer.rb#L15-L17 doesn't work anymore. I'm not sure how to fix this. I could use :full_path, but that returns (when normalized):

approvals_namers_directorynamer_uses_non_funky_example_description

instead of:

approvals_namers_directorynamer/uses_non_funky_example_description

@kytrinyx
Copy link
Contributor

kytrinyx commented Oct 9, 2014

doesn't work anymore

In what way does it not work?

Can you point me to the place in the code where it says that example group is deprecated? This is what it says in the master branch of rspec core:

https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/example_group.rb#L5-L6

@Willianvdv
Copy link
Contributor Author

Sorry for my bad "doesn't work" description. ':example_group itself is not deprecated but example[:example_group] is. You can still use it, but it will give a deprecation warning:

Deprecation Warnings:

The `:example_group` key in an example group's metadata hash is deprecated. Use the example
group's hash directly for the computed keys and `:parent_example_group` to access the parent
example group metadata instead. Called from 
~/src/approvals/lib/approvals/namers/directory_namer.rb:17:in `yield'.

@kytrinyx
Copy link
Contributor

kytrinyx commented Oct 9, 2014

Ah, so how about trying to call example.parent_example_group as suggested in the error message?

@Willianvdv
Copy link
Contributor Author

I tried, but the example's metadata hash doesn't have the :parent_example_group key. The example class itself also doesn't have a reference to parent_example_group (https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/example.rb).

Maybe it's super obvious, but I didn't figured it out yet :)

@kytrinyx
Copy link
Contributor

kytrinyx commented Oct 9, 2014

No not super-obvious.

OK, so what about instead of using the example_group key in the metadata hash, we access the example group directly from the example?

https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/example.rb#L110

I couldn't see a parent_example_group method on example_group at all, maybe it's possible to call example_group on an example_group:

https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/example_group.rb#L241

Inspired by VCR’s path implementation
@Willianvdv
Copy link
Contributor Author

VCR has the same construction. I borrowed their code and now the deprecation warning is gone! https://github.com/vcr/vcr/blob/master/lib/vcr/test_frameworks/rspec.rb#L10-L22

Thanks for your help @kytrinyx!

@Willianvdv Willianvdv changed the title [wip] Upgrade to RSpec 3 Upgrade to RSpec 3 Oct 9, 2014
@kytrinyx
Copy link
Contributor

kytrinyx commented Oct 9, 2014

Nice, thank you!

kytrinyx added a commit that referenced this pull request Oct 9, 2014
@kytrinyx kytrinyx merged commit 0cf1af7 into approvals:master Oct 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants