require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper') describe Rtml::WidgetCore::GuiConfiguration do subject { Rtml::WidgetCore::GuiConfiguration.new(Rtml::Widget) } context "with 1 field whose type is set to nil" do before :each do subject.fields[:name] = nil end it "infers :name, :caption and :type" do fields = subject.fields_with_inferences fields.should have(1).item field = fields.first field[:name].should == :name field[:type].should == :string field[:caption].should == 'Name' end end context "with 1 field whose type is set to :string" do before :each do subject.fields[:name] = :string end it "infers :name, :caption and :type" do fields = subject.fields_with_inferences fields.should have(1).item field = fields.first field[:name].should == :name field[:type].should == :string field[:caption].should == 'Name' end end context "with 1 field set from an array" do it "infers :name, :caption and :type given ['Name', :string]" do subject.fields[:name] = ['Name', :string] fields = subject.fields_with_inferences fields.should have(1).item field = fields.first field[:name].should == :name field[:type].should == :string field[:caption].should == 'Name' end it "infers :name, :caption and :type given [:string, 'Name']" do subject.fields[:name] = [:string, 'Name'] fields = subject.fields_with_inferences fields.should have(1).item field = fields.first field[:name].should == :name field[:type].should == :string field[:caption].should == 'Name' end it "infers :name, :caption and :type given [:string]" do subject.fields[:name] = [:string] fields = subject.fields_with_inferences fields.should have(1).item field = fields.first field[:name].should == :name field[:type].should == :string field[:caption].should == 'Name' end end context "with 1 field set from a hash" do before :each do subject.fields[:name] = {:caption => 'Name', :type => :string} end it "infers :name, :caption and :type" do fields = subject.fields_with_inferences fields.should have(1).item field = fields.first field[:name].should == :name field[:type].should == :string field[:caption].should == 'Name' end end context "with 2 fields" do context "set from a hash and a symbol" do before :each do subject.fields[:name] = {:caption => 'Name', :type => :string} subject.fields[:next] = :screen_ref end it "infers names, captions and types" do fields = subject.fields_with_inferences fields.should have(2).items field = fields.shift field[:name].should == :name field[:type].should == :string field[:caption].should == 'Name' field = fields.shift field[:name].should == :next field[:type].should == :screen_ref field[:caption].should == 'Next' end end end end