You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

running_test_case_spec.rb 3.3 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # frozen_string_literal: true
  2. require 'cucumber/running_test_case'
  3. require 'cucumber/core'
  4. require 'cucumber/core/gherkin/writer'
  5. module Cucumber
  6. describe RunningTestCase do
  7. include Core
  8. include Core::Gherkin::Writer
  9. attr_accessor :wrapped_test_case, :core_test_case
  10. let(:result) { double(:result, to_sym: :status_symbol) }
  11. before do
  12. receiver = double.as_null_object
  13. allow(receiver).to receive(:test_case) { |core_test_case|
  14. self.core_test_case = core_test_case
  15. self.wrapped_test_case = RunningTestCase.new(core_test_case).with_result(result)
  16. }
  17. compile [gherkin_doc], receiver
  18. end
  19. context 'for a regular scenario' do
  20. let(:gherkin_doc) do
  21. gherkin do
  22. feature 'feature name' do
  23. scenario 'scenario name' do
  24. step 'passing'
  25. end
  26. end
  27. end
  28. end
  29. it 'sets the scenario name correctly' do
  30. expect(wrapped_test_case.name).to eq 'scenario name'
  31. end
  32. it 'exposes properties of the test_case' do
  33. expect(wrapped_test_case.location).to eq core_test_case.location
  34. expect(wrapped_test_case.language).to eq core_test_case.language
  35. end
  36. it 'exposes properties of the result' do
  37. expect(wrapped_test_case.status).to eq result.to_sym
  38. end
  39. end
  40. context 'for a failed scenario' do
  41. let(:gherkin_doc) do
  42. gherkin do
  43. feature 'feature name' do
  44. scenario 'scenario name' do
  45. step 'failed'
  46. end
  47. end
  48. end
  49. end
  50. let(:exception) { StandardError.new }
  51. before do
  52. self.wrapped_test_case = wrapped_test_case.with_result(Core::Test::Result::Failed.new(0, exception))
  53. end
  54. it 'is failed?' do
  55. expect(wrapped_test_case.failed?).to be_truthy
  56. end
  57. it 'exposes the exception' do
  58. expect(wrapped_test_case.exception).to eq exception
  59. end
  60. end
  61. context 'for a passing scenario' do
  62. let(:gherkin_doc) do
  63. gherkin do
  64. feature 'feature name' do
  65. scenario 'scenario name' do
  66. step 'passing'
  67. end
  68. end
  69. end
  70. end
  71. before do
  72. self.wrapped_test_case = wrapped_test_case.with_result(Core::Test::Result::Passed.new(0))
  73. end
  74. it 'is not failed?' do
  75. expect(wrapped_test_case.failed?).to be_falsey
  76. end
  77. it '#exception is nil' do
  78. expect(wrapped_test_case.exception).to be_nil
  79. end
  80. end
  81. context 'for a scenario outline' do
  82. let(:gherkin_doc) do
  83. gherkin do
  84. feature 'feature name' do
  85. scenario_outline 'scenario outline name' do
  86. step 'passing with <arg1> <arg2>'
  87. examples 'examples name' do
  88. row 'arg1', 'arg2'
  89. row 'a', 'b'
  90. end
  91. end
  92. end
  93. end
  94. end
  95. it "sets the test case's name correctly" do
  96. expect(wrapped_test_case.name).to eq 'scenario outline name'
  97. end
  98. it 'exposes properties of the test_case' do
  99. expect(wrapped_test_case.location).to eq core_test_case.location
  100. expect(wrapped_test_case.language).to eq core_test_case.language
  101. end
  102. end
  103. end
  104. end

No Description

Contributors (1)