spec/statesman/adapters/shared_examples.rb in statesman-0.7.0 vs spec/statesman/adapters/shared_examples.rb in statesman-0.8.0

- old
+ new

@@ -12,99 +12,101 @@ # last: Returns the latest transition history item # shared_examples_for "an adapter" do |adapter_class, transition_class| let(:observer) do result = double(Statesman::Machine) - result.stub(:execute) + allow(result).to receive(:execute) result end let(:adapter) { adapter_class.new(transition_class, model, observer) } describe "#initialize" do subject { adapter } - its(:transition_class) { should be(transition_class) } - its(:parent_model) { should be(model) } - its(:history) { should eq([]) } + its(:transition_class) { is_expected.to be(transition_class) } + its(:parent_model) { is_expected.to be(model) } + its(:history) { is_expected.to eq([]) } end describe "#create" do let(:from) { :x } let(:to) { :y } let(:there) { :z } let(:create) { adapter.create(from, to) } subject { -> { create } } - it { should change(adapter.history, :count).by(1) } + it { is_expected.to change(adapter.history, :count).by(1) } context "the new transition" do subject { create } - it { should be_a(transition_class) } + it { is_expected.to be_a(transition_class) } it "should have the initial state" do expect(subject.to_state.to_sym).to eq(to) end context "with no previous transition" do - its(:sort_key) { should be(0) } + its(:sort_key) { is_expected.to be(0) } end context "with a previous transition" do before { adapter.create(from, to) } - its(:sort_key) { should be(10) } + its(:sort_key) { is_expected.to be(10) } end end context "with before callbacks" do it "is called before the state transition" do - observer.should_receive(:execute).with do - |phase, from_state, to_state, transition| - expect(adapter.history.length).to eq(0) if phase == :before - end.once + 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 - observer.should_receive(:execute).with do - |phase, from_state, to_state, transition| - expect(adapter.last).to eq(transition) if phase == :after - end.once + expect(observer).to receive(:execute) + .with(:after, anything, anything, anything) { + |_phase, _from_state, _to_state, 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) - observer.should_receive(:execute).with do - |phase, from_state, to_state, transition| - expect(adapter.last).to eq(transition) if phase == :after - end.once + expect(observer).to receive(:execute) + .with(:after, anything, anything, anything) { + |_phase, _from_state, _to_state, transition| + expect(adapter.last).to eq(transition) + }.once adapter.create(to, there) end end context "with metadata" do let(:metadata) { { "some" => "hash" } } subject { adapter.create(from, to, metadata) } - its(:metadata) { should eq(metadata) } + its(:metadata) { is_expected.to eq(metadata) } end end describe "#history" do subject { adapter.history } - it { should eq([]) } + it { is_expected.to eq([]) } context "with transitions" do let!(:transition) { adapter.create(:x, :y) } - it { should eq([transition]) } + it { is_expected.to eq([transition]) } context "sorting" do let!(:transition2) { adapter.create(:x, :y) } subject { adapter.history } - it { should eq(adapter.history.sort_by(&:sort_key)) } + it { is_expected.to eq(adapter.history.sort_by(&:sort_key)) } end end end describe "#last" do @@ -112,9 +114,9 @@ adapter.create(:x, :y) adapter.create(:y, :z) end subject { adapter.last } - it { should be_a(transition_class) } + it { is_expected.to be_a(transition_class) } specify { expect(adapter.last.to_state.to_sym).to eq(:z) } end end