spec/statesman/adapters/shared_examples.rb in statesman-3.4.1 vs spec/statesman/adapters/shared_examples.rb in statesman-3.5.0

- old
+ new

@@ -11,48 +11,50 @@ # history: Returns the full transition history # last: Returns the latest transition history item # # NOTE This line cannot reasonably be shortened. shared_examples_for "an adapter" do |adapter_class, transition_class, options = {}| - # rubocop:enable Metrics/LineLength - let(:observer) { double(Statesman::Machine, execute: nil) } let(:adapter) do adapter_class.new(transition_class, model, observer, options) end describe "#initialize" do subject { adapter } + 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 + subject { -> { create } } + let(:from) { :x } let(:to) { :y } let(:there) { :z } let(:create) { adapter.create(from, to) } - subject { -> { create } } it { is_expected.to change(adapter.history, :count).by(1) } context "the new transition" do - subject { create } + subject(:instance) { create } + it { is_expected.to be_a(transition_class) } - it "should have the initial state" do - expect(subject.to_state.to_sym).to eq(to) + it "has the initial state" do + expect(instance.to_state.to_sym).to eq(to) end context "with no previous transition" do its(:sort_key) { is_expected.to be(10) } end context "with a previous transition" do before { adapter.create(from, to) } + its(:sort_key) { is_expected.to be(20) } end end context "with before callbacks" do @@ -85,36 +87,43 @@ adapter.create(to, there) end end context "with metadata" do - let(:metadata) { { "some" => "hash" } } subject { adapter.create(from, to, metadata) } + + let(:metadata) { { "some" => "hash" } } + its(:metadata) { is_expected.to eq(metadata) } end end describe "#history" do subject { adapter.history } + it { is_expected.to eq([]) } context "with transitions" do let!(:transition) { adapter.create(:x, :y) } + it { is_expected.to eq([transition]) } context "sorting" do - let!(:transition2) { adapter.create(:x, :y) } subject { adapter.history } + let!(:transition2) { adapter.create(:x, :y) } + it { is_expected.to eq(adapter.history.sort_by(&:sort_key)) } end end end describe "#last" do + subject { adapter.last } + 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) } specify do expect(adapter.last(force_reload: true).to_state.to_sym).to eq(:z)