Sha256: 9b84d58dc8a9a882bc1a8b2e40dee232d6fae4da5b35f5043e543e30290a28aa

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'logirel/q_model'

describe Logirel::StrQ, "in its default mode of operation, when reading props" do
  before(:each) { @q = StrQ.new "Q??", "def" }
  subject { @q }
  it { should respond_to :question }
  it { should respond_to :default }
  specify { @q.answer.should eql("def") }
  specify { @q.question.should eql("Q??") }
end

describe Logirel::StrQ, "when feeding it OK input" do
  before(:each) do 
    @io = StringIO.new "My Answer"
    @out = StringIO.new
    @validator = double('validator')
    @validator.should_receive(:call).once.
      with(an_instance_of(String)).
      and_return(true)
  end
  subject { StrQ.new("q?", "def", @io, @validator, @out) }
  specify { 
    subject.exec.should eql("My Answer") and 
    subject.answer.should eql("My Answer") 
  }
end

describe Logirel::StrQ, "when feeding it bad input" do
  before(:each) do 
    @io = StringIO.new "My Bad Answer\nAnother Bad Answer\nOKAnswer!"
    @out = StringIO.new
	
    @validator = double('validator')
    @validator.should_receive(:call).exactly(3).times.
      with(an_instance_of(String)).
      and_return(false, false, true)
  end
  subject { StrQ.new("q?", "def", @io, @validator, @out) }
  specify { subject.exec.should == "OKAnswer!" }
end

describe Logirel::StrQ, "when accepting the defaults" do
  before(:each) do 
    @io = StringIO.new "\n"
    @out = StringIO.new
	
    @validator = double('validator')
    @validator.should_receive(:call).once.
      with(an_instance_of(String)).
	# the validator should be called for empty input once if we have a default, directly when defaulting with validator{true}
      and_return(true)
  end
  subject { StrQ.new("q?", "def", @io, @validator, @out) }
  specify {
    subject.exec.should eql("def") and 
    subject.answer.should eql("def") 
  }
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logirel-0.0.15 spec/queries/string_query_spec.rb