Sha256: a5dc62a85ad8566221ef31103585d77517947ea501effc07b240f7af32895703

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

class FlowTest < Cascadence::Flow

  cascading_order :step1, :step2, :step3, :step4

  def initialize
    self.state = "initialized"
  end

  def step1
    self.state += "-step1"
  end

  def step2
    self.state += "-step2"
  end

  def step3
    self.state += "-step3"
  end

  def step4
    self.state += "-step4"
  end

end

describe Cascadence::Flow do

  before :each do
    @flow = FlowTest.new
  end

  describe "#subclasses" do
    context "deep inheritance" do
      let(:inception) do
        Class.new Class.new Class.new Class.new FlowTest
      end

      it "should increase the members in subclasses even though it's not directly inheriting one thing" do
        expect { inception }.to change(Cascadence::Flow.subclasses, :count).by 4
      end
      it "should at least contain the give class" do
        Cascadence::Flow.subclasses.should include inception
      end
    end
  end

  describe "sanity" do

    it "should be an instance of flowtest" do
      @flow.class.should eq FlowTest
    end

    it "should respond to state" do
      @flow.should respond_to :state
      @flow.should respond_to :state=
      @flow.state.should eq "initialized"
    end 

    it "should be an instance of cascadence::flow" do
      FlowTest.superclass.should eq Cascadence::Flow
    end

  end

  describe "#subclasses" do
    let(:inherit) { Class.new(Cascadence::Flow) }

    it "should change the count of subclasses by 1" do
      expect { inherit }.to change(Cascadence::Flow.subclasses, :count).by(1)
    end
    it "should include this new mixed in class as a subclass of cascadence flow" do
      Cascadence::Flow.subclasses.should include inherit
    end
  end

  describe "#run_states" do

    before(:each) { @expected = "initialized-step1-step2-step3-step4" }
    let(:actual) { @flow.run_states }

    it "should run all four states in the specified cascading order" do
      actual.state.should eq @expected
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cascadence-0.4.5 spec/cascadence/flow_spec.rb
cascadence-0.4.4 spec/cascadence/flow_spec.rb
cascadence-0.4.3 spec/cascadence/flow_spec.rb
cascadence-0.3.0 spec/cascadence/flow_spec.rb
cascadence-0.2.4 spec/cascadence/flow_spec.rb
cascadence-0.2.3 spec/cascadence/flow_spec.rb