spec/statesman/adapters/shared_examples.rb in statesman-1.1.0 vs spec/statesman/adapters/shared_examples.rb in statesman-1.2.0
- old
+ new
@@ -10,15 +10,11 @@
# instance and saves metadata to it.
# history: Returns the full transition history
# last: Returns the latest transition history item
#
shared_examples_for "an adapter" do |adapter_class, transition_class|
- let(:observer) do
- result = double(Statesman::Machine)
- allow(result).to receive(:execute)
- result
- end
+ let(:observer) { double(Statesman::Machine, execute: nil) }
let(:adapter) { adapter_class.new(transition_class, model, observer) }
describe "#initialize" do
subject { adapter }
its(:transition_class) { is_expected.to be(transition_class) }
@@ -53,35 +49,33 @@
end
end
context "with before callbacks" do
it "is called before the state transition" do
- expect(observer).to receive(:execute)
- .with(:before, anything, anything, anything) {
+ expect(observer).to receive(:execute).
+ with(:before, anything, anything, anything) {
expect(adapter.history.length).to eq(0)
}.once
adapter.create(from, to)
expect(adapter.history.length).to eq(1)
end
end
context "with after callbacks" do
it "is called after the state transition" do
- expect(observer).to receive(:execute)
- .with(:after, anything, anything, anything) {
- |_phase, _from_state, _to_state, transition|
+ expect(observer).to receive(:execute).
+ with(:after, anything, anything, anything) { |_, _, _, transition|
expect(adapter.last).to eq(transition)
}.once
adapter.create(from, to)
end
it "exposes the new transition for subsequent transitions" do
adapter.create(from, to)
- expect(observer).to receive(:execute)
- .with(:after, anything, anything, anything) {
- |_phase, _from_state, _to_state, transition|
+ expect(observer).to receive(:execute).
+ with(:after, anything, anything, anything) { |_, _, _, transition|
expect(adapter.last).to eq(transition)
}.once
adapter.create(to, there)
end
end
@@ -102,19 +96,18 @@
it { is_expected.to eq([transition]) }
context "sorting" do
let!(:transition2) { adapter.create(:x, :y) }
subject { adapter.history }
+
it { is_expected.to eq(adapter.history.sort_by(&:sort_key)) }
end
end
end
describe "#last" do
- before do
- adapter.create(:x, :y)
- adapter.create(:y, :z)
- end
+ before { adapter.create(:x, :y) }
+ before { adapter.create(:y, :z) }
subject { adapter.last }
it { is_expected.to be_a(transition_class) }
specify { expect(adapter.last.to_state.to_sym).to eq(:z) }
end