1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
require 'cucumber/core/test/action'
require 'cucumber/core/test/duration_matcher'
module Cucumber
module Core
module Test
describe Action do
context "constructed without a block" do
it "raises an error" do
expect { Action.new }.to raise_error(ArgumentError)
end
end
context "location" do
context "with location passed to the constructor" do
let(:location) { double }
it "returns the location passed to the constructor" do
action = Action.new(location) {}
expect( action.location ).to be location
end
end
context "without location passed to the constructor" do
let(:block) { proc {} }
it "returns the location of the block passed to the constructor" do
action = Action.new(&block)
expect( action.location ).to eq Ast::Location.new(*block.source_location)
end
end
end
context "executing" do
it "executes the block passed to the constructor" do
executed = false
action = Action.new { executed = true }
action.execute
expect( executed ).to be_truthy
end
it "returns a passed result if the block doesn't fail" do
action = Action.new {}
expect( action.execute ).to be_passed
end
it "returns a failed result when the block raises an error" do
exception = StandardError.new
action = Action.new { raise exception }
result = action.execute
expect( result ).to be_failed
expect( result.exception ).to eq exception
end
it "yields the args passed to #execute to the block" do
args = [double, double]
args_spy = nil
action = Action.new { |arg1, arg2| args_spy = [arg1, arg2] }
action.execute(*args)
expect(args_spy).to eq args
end
it "returns a pending result if a Result::Pending error is raised" do
exception = Result::Pending.new("TODO")
action = Action.new { raise exception }
result = action.execute
expect( result ).to be_pending
expect( result.message ).to eq "TODO"
end
it "returns a skipped result if a Result::Skipped error is raised" do
exception = Result::Skipped.new("Not working right now")
action = Action.new { raise exception }
result = action.execute
expect( result ).to be_skipped
expect( result.message ).to eq "Not working right now"
end
it "returns an undefined result if a Result::Undefined error is raised" do
exception = Result::Undefined.new("new step")
action = Action.new { raise exception }
result = action.execute
expect( result ).to be_undefined
expect( result.message ).to eq "new step"
end
context "recording the duration" do
before do
allow( Timer::MonotonicTime ).to receive(:time_in_nanoseconds).and_return(525702744080000, 525702744080001)
end
it "records the nanoseconds duration of the execution on the result" do
action = Action.new { }
duration = action.execute.duration
expect( duration ).to be_duration 1
end
it "records the duration of a failed execution" do
action = Action.new { raise StandardError }
duration = action.execute.duration
expect( duration ).to be_duration 1
end
end
end
context "skipping" do
it "does not execute the block" do
executed = false
action = Action.new { executed = true }
action.skip
expect( executed ).to be_falsey
end
it "returns a skipped result" do
action = Action.new {}
expect( action.skip ).to be_skipped
end
end
end
describe UndefinedAction do
let(:location) { double }
let(:action) { UndefinedAction.new(location) }
let(:test_step) { double }
context "location" do
it "returns the location passed to the constructor" do
expect( action.location ).to be location
end
end
context "executing" do
it "returns an undefined result" do
expect( action.execute ).to be_undefined
end
end
context "skipping" do
it "returns an undefined result" do
expect( action.skip ).to be_undefined
end
end
end
end
end
end
|