Permalink
Browse files

doc tweaks

  • Loading branch information...
1 parent 5e035ea commit 98f811deb28dc1ecf15fb9cec08673c2f480cff4 @dchelimsky dchelimsky committed Apr 17, 2011
Showing with 39 additions and 88 deletions.
  1. +26 −79 features/example_groups/shared_context.feature
  2. +13 −9 features/example_groups/shared_example_group.feature
@@ -3,9 +3,9 @@ Feature: shared context
Use `shared_context` to define a block that will be evaluated in the context
of example groups either explicitly, using `include_context`, or implicitly by
matching metdata.
-
- Scenario: declare and use shared context with a string name
- Given a file named "shared_context_spec.rb" with:
+
+ Background:
+ Given a file named "shared_stuff.rb" with:
"""
shared_context "shared stuff", :a => :b do
before { @some_var = :some_value }
@@ -17,8 +17,16 @@ Feature: shared context
'this is the subject'
end
end
+ """
+
+ Scenario: declare shared context and include it with include_context
+ Given a file named "shared_context_example.rb" with:
+ """
+ require "./shared_stuff.rb"
+
+ describe "group that includes a shared context using 'include_context'" do
+ include_context "shared stuff"
- shared_examples "group including shared context" do
it "has access to methods defined in shared context" do
shared_method.should eq("it works")
end
@@ -35,93 +43,32 @@ Feature: shared context
subject.should eq('this is the subject')
end
end
-
- describe "group that includes a shared context using 'include_context'" do
- include_context "shared stuff"
- it_behaves_like "group including shared context"
- end
-
- describe "group that includes a shared context using metadata", :a => :b do
- it_behaves_like "group including shared context"
- end
- """
- When I run `rspec shared_context_spec.rb`
- Then the output should contain "8 examples"
- And the examples should all pass
-
- Scenario: share a method
- Given a file named "shared_context_spec.rb" with:
- """
- shared_context :type => :special do
- def shared_method
- "it works"
- end
- end
-
- describe "something", :type => :special do
- it "access methods defined in configuration" do
- shared_method.should eq("it works")
- end
- end
"""
- When I run `rspec shared_context_spec.rb`
+ When I run `rspec shared_context_example.rb`
Then the examples should all pass
- Scenario: share a `let` declaration
- Given a file named "shared_context_spec.rb" with:
+ Scenario: declare shared context and include it with metadata
+ Given a file named "shared_context_example.rb" with:
"""
- shared_context :type => :special do
- let(:method_defined_by_let_in_config) { "it works" }
- end
+ require "./shared_stuff.rb"
- describe "something", :type => :special do
- it "access methods defined using let in configuration" do
- method_defined_by_let_in_config.should eq("it works")
+ describe "group that includes a shared context using metadata", :a => :b do
+ it "has access to methods defined in shared context" do
+ shared_method.should eq("it works")
end
- end
- """
- When I run `rspec shared_context_spec.rb`
- Then the examples should all pass
- Scenario: share a subject
- Given a file named "shared_context_spec.rb" with:
- """
- shared_context :type => :special do
- subject { :subject_defined_in_configuration }
- end
-
- describe "something", :type => :special do
- it "uses the subject defined in configuration" do
- subject.should be(:subject_defined_in_configuration)
+ it "has access to methods defined with let in shared context" do
+ shared_let['arbitrary'].should eq('object')
end
- end
- """
- When I run `rspec shared_context_spec.rb`
- Then the examples should all pass
-
- @wip
- 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
- end
-
- shared_context :special do
- let(:help) { :available }
- end
- describe "something", :special do
- it "accesses helper methods defined using `let` in the configuration" do
- help.should be(:available)
+ it "runs the before hooks defined in the shared context" do
+ @some_var.should be(:some_value)
end
- end
- describe "something else" do
- it "cannot access helper methods defined using `let` in the configuration" do
- expect { help }.to raise_error(NameError)
+ it "accesses the subject defined in the shared context" do
+ subject.should eq('this is the subject')
end
end
"""
- When I run `rspec use_symbols_as_metadata_spec.rb`
+ When I run `rspec shared_context_example.rb`
Then the examples should all pass
@@ -1,14 +1,18 @@
-Feature: shared example group
+Feature: shared examples
- Shared example groups let you describe behaviour of types or modules. When
+ Shared examples let you describe behaviour of types or modules. When
declared, a shared group's content is stored. It is only realized in the
context of another example group, which provides any context the shared group
needs to run.
- A shared group is included in another group using the it_behaves_like() or
- it_should_behave_like() methods.
+ A shared group is included in another group using any of:
+
+ include_examples "name" # include the examples in the current context
- Scenario: shared example group applied to two groups
+ it_behaves_like "name" # include the examples in a nested context
+ it_should_behave_like "name" # include the examples in a nested context
+
+ Scenario: shared examples group included in two groups
Given a file named "collection_spec.rb" with:
"""
require "set"
@@ -86,13 +90,13 @@ Feature: shared example group
end
describe Array do
- it_should_behave_like "a collection object" do
+ it_behaves_like "a collection object" do
let(:collection) { Array.new }
end
end
describe Set do
- it_should_behave_like "a collection object" do
+ it_behaves_like "a collection object" do
let(:collection) { Set.new }
end
end
@@ -102,12 +106,12 @@ Feature: shared example group
And the output should contain:
"""
Array
- it should behave like a collection object
+ behaves like a collection object
<<
adds objects to the end of the collection
Set
- it should behave like a collection object
+ behaves like a collection object
<<
adds objects to the end of the collection
"""

0 comments on commit 98f811d

Please sign in to comment.