Alias example group #1255

merged 22 commits into from Jan 28, 2014


None yet
3 participants

myronmarston commented Jan 22, 2014

This is a follow up to #1236. It's @michihuber's work plus the start of fixes I've applied based on mine and @JonRowe's feedback on that PR. This supercedes that PR.

myronmarston referenced this pull request Jan 22, 2014


Alias example group #1236

michihuber and others added some commits Apr 8, 2013

@michihuber @myronmarston michihuber first aliasing feature bb61140
@michihuber @myronmarston michihuber ExampleGroup#alias_example_group_to acf7bad
@michihuber @myronmarston michihuber rename #describe to #example_group
@michihuber @myronmarston michihuber use new metadata interface be029ce
@michihuber @myronmarston michihuber expose example group aliases on RSpec and globally if configured 78a82ad
@myronmarston myronmarston Cleanup docs a bit. a5a09c1
@myronmarston myronmarston Standardize on `__send__` over `send`.
We've occasionally received bug reports related to
users having objects that redefine `send` (e.g.
`Email#send`), and using `__send__` is best to avoid
those problems.

Many of the receivers of `__send__` here are objects
we own and that do not (and never will) redefine `send`;
however, for consistency, it's good to standardize on
`__send__`. That way, we're less likely to forget it in
the future for a case where it does matter.
@myronmarston myronmarston Add missing spec.
This already worked but wasn't covered by a test.
@myronmarston myronmarston Improve DSL specs.
- Cover all the edge cases.
- Use a subprocess for global config changes.
- No need to use a separate example group per method.
  It adds to the runtime of the test suite with no benefit.
@myronmarston myronmarston Ensure example group aliases are exposed globally if so configured.
Before, they were not exposed globally if the config option
was already set.
@myronmarston myronmarston Cleanup how the DSL is defined.
- No need to use send.
- Extract change_global_dsl helper method.
@myronmarston myronmarston Update ignored method cache busters. dc5bec9
@myronmarston myronmarston Fix invalid 1.8.7 syntax. 22aa6ba

michihuber commented Jan 23, 2014

Thanks @myronmarston for taking over!
(I just came back online, which is why I couldn't continue working on this earlier.)


myronmarston commented Jan 24, 2014

OK, I think this is ready to merge. @michihuber / @JonRowe -- care to review what I've done on top of #1236?


myronmarston commented Jan 28, 2014

Anyone want to review this?

/cc @JonRowe @xaviershay @samphippen @alindeman @soulcutter

@JonRowe JonRowe commented on the diff Jan 28, 2014

+ example group in order to temporarily disable the examples.
+ * `fdescribe` and `fcontext` add `:focus` metadata to the
+ example group in order to make it easy to temporarily
+ focus the example group (when combined with `config.filter_run :focus`.)
+ Scenario: custom example group aliases with metadata
+ Given a file named "nested_example_group_aliases_spec.rb" with:
+ """ruby
+ RSpec.configure do |c|
+ c.alias_example_group_to :detail, :detailed => true
+ end
+ RSpec.detail "a detail" do
+ it "can do some less important stuff" do
+ end
+ end

JonRowe Jan 28, 2014


This doesn't "prove" the :detailed => true part of the alias, do we care? Perhaps we could assert on the metadata?

Scratch that I see you're using tags.


myronmarston Jan 28, 2014


Honestly, I'm not super happy with this cucumber example. Got a better idea?

@JonRowe JonRowe commented on the diff Jan 28, 2014

+ changing_expose_dsl_globally do
+ RSpec.configuration.expose_dsl_globally = true
+ expect(RSpec.configuration.expose_dsl_globally?).to eq true
+ end
+ yield
+ end
+ end
+ it 'are only available off of `RSpec`, `main` and modules' do
+ enable do
+ expect(::RSpec).to respond_to(*method_names)
+ expect(main).to respond_to(*method_names)
+ expect( respond_to(*method_names)
+ expect( respond_to(*method_names)

JonRowe Jan 28, 2014


Did not know you could splat method names into that...

@JonRowe JonRowe commented on an outdated diff Jan 28, 2014

lib/rspec/core/shared_example_group.rb: undef shared_examples
lib/rspec/core/shared_example_group.rb: undef shared_context
lib/rspec/core/shared_example_group.rb: undef share_examples_for
lib/rspec/core/shared_example_group.rb: undef shared_examples_for
lib/rspec/core/shared_example_group.rb: undef shared_example_groups
-lib/rspec/core/shared_example_group.rb: Core::DSL.top_level.instance_eval(&to_undefine)
-lib/rspec/core/shared_example_group.rb: Module.class_exec(&to_undefine)

JonRowe Jan 28, 2014


Stray whitespace... ;)


JonRowe commented Jan 28, 2014

Apart from my white space niggle, LGTM :P

myronmarston merged commit 729f2f7 into master Jan 28, 2014

1 check passed

default The Travis CI build passed

myronmarston deleted the pr-1236-rebased branch Jan 28, 2014

xaviershay changed the title from Pr 1236 rebased to Alias example group Apr 27, 2014

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