PageRenderTime 38ms CodeModel.GetById 11ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/rspec-core-2.14.8/features/example_groups/shared_context.feature

https://github.com/delowong/logstash
Gherkin Specification | 74 lines | 61 code | 13 blank | 0 comment | 2 complexity | 72006ccbf1535fd11d4c11f58d50d48d MD5 | raw file
 1Feature: shared context
 2
 3  Use `shared_context` to define a block that will be evaluated in the context
 4  of example groups either explicitly, using `include_context`, or implicitly by
 5  matching metadata.
 6
 7  Background:
 8    Given a file named "shared_stuff.rb" with:
 9      """ruby
10      shared_context "shared stuff", :a => :b do
11        before { @some_var = :some_value }
12        def shared_method
13          "it works"
14        end
15        let(:shared_let) { {'arbitrary' => 'object'} }
16        subject do
17          'this is the subject'
18        end
19      end
20      """
21
22  Scenario: declare shared context and include it with include_context
23    Given a file named "shared_context_example.rb" with:
24      """ruby
25      require "./shared_stuff.rb"
26
27      describe "group that includes a shared context using 'include_context'" do
28        include_context "shared stuff"
29
30        it "has access to methods defined in shared context" do
31          shared_method.should eq("it works")
32        end
33
34        it "has access to methods defined with let in shared context" do
35          shared_let['arbitrary'].should eq('object')
36        end
37
38        it "runs the before hooks defined in the shared context" do
39          @some_var.should be(:some_value)
40        end
41
42        it "accesses the subject defined in the shared context" do
43          subject.should eq('this is the subject')
44        end
45      end
46      """
47    When I run `rspec shared_context_example.rb`
48    Then the examples should all pass
49
50  Scenario: declare shared context and include it with metadata
51    Given a file named "shared_context_example.rb" with:
52      """ruby
53      require "./shared_stuff.rb"
54
55      describe "group that includes a shared context using metadata", :a => :b do
56        it "has access to methods defined in shared context" do
57          shared_method.should eq("it works")
58        end
59
60        it "has access to methods defined with let in shared context" do
61          shared_let['arbitrary'].should eq('object')
62        end
63
64        it "runs the before hooks defined in the shared context" do
65          @some_var.should be(:some_value)
66        end
67
68        it "accesses the subject defined in the shared context" do
69          subject.should eq('this is the subject')
70        end
71      end
72      """
73    When I run `rspec shared_context_example.rb`
74    Then the examples should all pass