Sha256: 7b0b7e4f6728e1ea78240d954415f133ec0843fcd8ec2145bd3d3f8190bb1498

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

require 'helper'

class Engine
  follows_the_rules!
  
  attr_accessor :state
  
  def initialize
    @state = :off
  end

  rulebook.add(/is_(off|idle|broken)/) do |state|
    @state = state.to_sym
    self
  end

  rulebook.add(/is_(off|idle|broken)\?/) do |state|
    @state == state.to_sym
  end
end

context "A Chevy engine" do
  setup { Engine.new }

  context "that is off" do
    asserts_topic.assigns(:state, :off)
    asserts(:state).equals(:off)
  end

  context "that is idle" do
    setup { topic.is_idle }
    asserts_topic.assigns(:state, :idle)
    asserts(:state).equals(:idle)
  end

  context "that is broken as usual" do
    setup { topic.is_broken }
    asserts_topic.assigns(:state, :broken)
  end

  context "checked with custom rule" do
    context "that is off" do
      asserts(:is_off?)
    end

    context "that is idle" do
      setup { topic.is_idle }
      asserts(:is_idle?)
    end

    context "that is broken as usual" do
      setup { topic.is_broken }
      asserts(:is_broken?)
    end
  end
end 

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rulebook-0.4.3 test/test_chevy.rb
rulebook-0.4.2 test/test_chevy.rb
rulebook-0.4.1 test/test_chevy.rb
rulebook-0.4.0 test/test_chevy.rb