Sha256: 28c50d8b51188142ffb465734b91a405321ab43a1a1edf5290ef97738de37600

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

describe Restfulie::Client::Mikyung::WhenCondition do
  
  before do
    @rule = [""]
    @params = Object.new
    @condition = Restfulie::Client::Mikyung::WhenCondition.new(nil, @rule, @params)
    @resource = Object.new
    @goal = Object.new
    @mikyung = Object.new
  end

  it "should execute for every result concatenated" do
    obj = Object.new
    def obj.description
      "will execute something special"
    end
    @condition.results_on obj
    
    result = Object.new
    obj.should_receive(:execute).with(@resource, @goal, @mikyung).and_return(result)
    
    @condition.execute(@resource, @goal, @mikyung).should == result
  end
  
  it "should not run if its rule without params does not match" do
    @rule << lambda { |without| false }
    @condition.should_run_for(@resource, @goal).should be_false
  end

  it "should not run if its rule with params does not match" do
    @rule << lam(false)
    @condition.should_run_for(@resource, @goal).should be_false
  end
  
  def lam(what)
    lambda { |without, regex| what }
  end
  
  it "should run if its rule says so" do
    @rule << lam(true)
    @condition.should_run_for(@resource, @goal).should be_true
  end
  
  it "should run if its rule and extras says so" do
    @rule << lam(true)
    @condition.and Restfulie::Client::Mikyung::WhenCondition.new(nil, ["", lam(true)], @params)
    @condition.should_run_for(@resource, @goal).should be_true
  end
  
  it "should not run if its rule says yes but extras no" do
    @rule << lam(true)
    @condition.and Restfulie::Client::Mikyung::WhenCondition.new(nil, ["", lam(false)], @params)
    @condition.should_run_for(@resource, @goal).should be_false
  end
  
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
restfulie-nosqlite-1.0.4 spec/unit/client/mikyung/when_condition_spec.rb
restfulie-1.1.1 spec/unit/client/mikyung/when_condition_spec.rb
restfulie-1.1.0 spec/unit/client/mikyung/when_condition_spec.rb
restfulie-nosqlite-1.0.3 spec/unit/client/mikyung/when_condition_spec.rb
restfulie-1.0.3 spec/unit/client/mikyung/when_condition_spec.rb