spec/stylesheet_spec.rb in teacup-1.2.5 vs spec/stylesheet_spec.rb in teacup-1.2.7

- old
+ new

@@ -49,19 +49,19 @@ @stylesheet = Teacup::Stylesheet.new do style :example_button, title: "Example!", frame: [[0, 0], [100, 100]], layer: { - borderRadius: 10, + borderWidth: 10, opacity: 0.5 } style :example_button, backgroundColor: :blue, frame: [[100, 100], [200, 200]], layer: { - borderRadius: 20 + borderWidth: 20 } end end it 'should union different properties' do @@ -71,12 +71,12 @@ it 'should give later properties precedence' do @stylesheet.query(:example_button)[:frame].should == [[100, 100], [200, 200]] end - it 'should give merge hashes' do - @stylesheet.query(:example_button)[:layer][:borderRadius].should == 20 + it 'should merge hashes' do + @stylesheet.query(:example_button)[:layer][:borderWidth].should == 20 @stylesheet.query(:example_button)[:layer][:opacity].should == 0.5 end end describe 'when a stylename extends another' do @@ -120,16 +120,23 @@ before do @oo_name_importer = Teacup::Stylesheet.new do import :importedbyname style :label, - backgroundColor: :blue + backgroundColor: :blue, + layer: { + borderWidth: 2, + } end Teacup::Stylesheet.new(:importedbyname) do style :label, - title: "Imported by name" + title: "Imported by name", + layer: { + borderWidth: 1, + borderColor: :red, + } end @name_importer = Teacup::Stylesheet.new do import :importedbyname @@ -165,10 +172,15 @@ it 'should work with a name even if defined out of order' do @oo_name_importer.query(:label)[:title].should == "Imported by name" @oo_name_importer.query(:label)[:backgroundColor].should == :blue end + it 'should merge properties' do + @oo_name_importer.query(:label)[:layer][:borderWidth].should == 2 + @oo_name_importer.query(:label)[:layer][:borderColor].should == :red + end + it 'should work with a value' do imported_anonymously = Teacup::Stylesheet.new do style :label, title: "Imported anonymously" end @@ -212,11 +224,11 @@ @stylesheet = Teacup::Stylesheet.new :stylesheet do import :most_generic style :label, - borderRadius: 10, + borderWidth: 10, title: "Stylesheet" end @most_specific = Teacup::Stylesheet.new :most_specific do import :stylesheet @@ -225,23 +237,29 @@ title: "Most specific", font: "IMPACT" end end + after do + Teacup::Stylesheet.stylesheets.delete(:most_generic) + Teacup::Stylesheet.stylesheets.delete(:stylesheet) + Teacup::Stylesheet.stylesheets.delete(:most_specific) + end + it 'should union different properties for the same rule' do @stylesheet.query(:label)[:backgroundColor].should == :blue - @stylesheet.query(:label)[:borderRadius] == 10 + @stylesheet.query(:label)[:borderWidth] == 10 end it 'should give the importer precedence' do @stylesheet.query(:label)[:title].should == "Stylesheet" end it 'should follow chains of imports' do @most_specific.query(:label)[:title].should == "Most specific" @most_specific.query(:label)[:font].should == "IMPACT" - @most_specific.query(:label)[:borderRadius].should == 10 + @most_specific.query(:label)[:borderWidth].should == 10 @most_specific.query(:label)[:backgroundColor].should == :blue end it 'should allow querying a rule which exists only in the importee' do @stylesheet.query(:button)[:title].should == "Click Here!" @@ -293,56 +311,56 @@ style :textfield, text: "Extended", backgroundColor: :blue style :my_textfield, extends: [:textfield, :input], - borderRadius: 10 + borderWidth: 10 end stylesheet.query(:my_textfield)[:text].should == "Extended" stylesheet.query(:my_textfield)[:backgroundColor].should == :blue stylesheet.query(:my_textfield)[:origin].should == [0, 0] - stylesheet.query(:my_textfield)[:borderRadius].should == 10 + stylesheet.query(:my_textfield)[:borderWidth].should == 10 end it 'should give precedence to imported rules over extended rules' do stylesheet = Teacup::Stylesheet.new do style :textfield, text: "Extended", backgroundColor: :blue style :my_textfield, extends: :textfield, - borderRadius: 10 + borderWidth: 10 import Teacup::Stylesheet.new{ style :my_textfield, text: "Imported" } end stylesheet.query(:my_textfield)[:text].should == "Imported" stylesheet.query(:my_textfield)[:backgroundColor].should == :blue - stylesheet.query(:my_textfield)[:borderRadius].should == 10 + stylesheet.query(:my_textfield)[:borderWidth].should == 10 end it 'should import rules using a deep merge strategy' do stylesheet = Teacup::Stylesheet.new do import Teacup::Stylesheet.new{ style :my_textfield, layer: { - borderRadius: 1, + borderWidth: 1, opacity: 0.5 } } style :my_textfield, layer: { - borderRadius: 10 + borderWidth: 10 } end stylesheet.query(:my_textfield)[:layer][:opacity].should == 0.5 - stylesheet.query(:my_textfield)[:layer][:borderRadius].should == 10 + stylesheet.query(:my_textfield)[:layer][:borderWidth].should == 10 end end end