Permalink
Browse files

Allow symbols to be treated as metadata for `config.for_groups_matchi…

…ng`.
  • Loading branch information...
1 parent 1dea593 commit 9cee5e286a768be34c7bceda48d2d806e7b445bc @myronmarston myronmarston committed Mar 9, 2011
@@ -3,6 +3,9 @@ Feature: for groups matching
Use `for_groups_matching` to define a block that will be evaluated
in the context of any example groups that have matching metadata.
+ If you set the `treat_symbols_as_metadata_keys_with_true_values` config option
+ to `true`, you can specify metadata using only symbols.
+
Scenario: define method for groups matching metadata
Given a file named "for_groups_matching_spec.rb" with:
"""
@@ -58,3 +61,28 @@ Feature: for groups matching
"""
When I run "rspec for_groups_matching_spec.rb"
Then the examples should all pass
+
+ Scenario: Use symbols as metadata
+ Given a file named "use_symbols_as_metadata_spec.rb" with:
+ """
+ RSpec.configure do |c|
+ c.treat_symbols_as_metadata_keys_with_true_values = true
+ c.for_groups_matching :special do
+ let(:help) { :available }
+ end
+ end
+
+ describe "something", :special do
+ it "accesses helper methods defined using `let` in the configuration" do
+ help.should be(:available)
+ end
+ end
+
+ describe "something else" do
+ it "cannot access helper methods defined using `let` in the configuration" do
+ expect { help }.to raise_error(NameError)
+ end
+ end
+ """
+ When I run "rspec use_symbols_as_metadata_spec.rb"
+ Then the examples should all pass
@@ -394,12 +394,12 @@ def configure_group(group)
# let(:valid_attributes) { Factory.attributes_for described_class.to_sym }
# end
# end
- def for_groups_matching(filters = {}, &block)
+ def for_groups_matching(*args, &block)
mod = Module.new
(class << mod; self; end).send(:define_method, :extended) do |host|
host.class_eval(&block)
end
- self.extend(mod, filters)
+ self.extend(mod, *args)
end
def configure_mock_framework
@@ -795,6 +795,15 @@ def metadata_hash(*args)
end
end
+ describe "#for_groups_matching" do
+ it_behaves_like "metadata hash builder" do
+ def metadata_hash(*args)
+ config.for_groups_matching(*args) { }
+ config.include_or_extend_modules.last.last
+ end
+ end
+ end
+
describe "#for_groups_matching" do
let(:matching_group) { ExampleGroup.describe(Array, :extended => true) }
let(:non_matching_group) { ExampleGroup.describe(Array) }

0 comments on commit 9cee5e2

Please sign in to comment.