/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

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