Skip to content

Commit

Permalink
Upgrade rspec, correct tests, and bump to v0.2.6 for multi-line selec…
Browse files Browse the repository at this point in the history
…tors
  • Loading branch information
mzsanford committed Nov 20, 2015
1 parent 17d3815 commit 3a99799
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 54 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -23,6 +23,7 @@ Report bugs in the github project at http://github.com/mzsanford/r2rb

## Change Log

* v0.2.6 - Handle multi-row selectors (fix from [@n0nick](https://github.com/n0nick))
* v0.2.5 - Handle `background:` shorthand
* v0.2.4 - Handle `url()` properties better
* [BUG] - Handle `url()` without embedded semi-colons and with trailing parameters
Expand Down
2 changes: 1 addition & 1 deletion lib/r2/version.rb
@@ -1,3 +1,3 @@
module R2
VERSION = "0.2.5"
VERSION = "0.2.6"
end
5 changes: 3 additions & 2 deletions r2.gemspec
Expand Up @@ -14,8 +14,9 @@ Gem::Specification.new do |s|

s.rubyforge_project = "r2"

s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 2.13.0'
s.add_development_dependency 'rake', '~> 0'
s.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
s.add_development_dependency 'rspec-mocks', '~> 3.4.0', '>= 3.4.0'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Expand Down
102 changes: 51 additions & 51 deletions spec/r2_spec.rb
Expand Up @@ -8,8 +8,8 @@
let(:css) { "body { direction: rtl; }" }

it "provides a shortcut to .new#r2" do
R2::Swapper.should_receive(:new).and_return(r2)
r2.should_receive(:r2).with(css)
allow(R2::Swapper).to receive(:new).and_return(r2)
expect(r2).to receive(:r2).with(css)
R2.r2(css)
end
end
Expand All @@ -21,7 +21,7 @@

describe "#r2" do
it "processes CSS" do
r2.r2("/* comment */\nbody { direction: rtl; }\nimg { padding: 4px;}").should == "body{direction:ltr;}img{padding:4px;}"
expect(r2.r2("/* comment */\nbody { direction: rtl; }\nimg { padding: 4px;}")).to eq("body{direction:ltr;}img{padding:4px;}")
end

it "handles media queries" do
Expand All @@ -37,7 +37,7 @@

flipped_css = r2.r2(css)

flipped_css.should == expected_result
expect(flipped_css).to eq(expected_result)
end

it "handles background-image declarations" do
Expand All @@ -52,7 +52,7 @@

flipped_css = r2.r2(css)

flipped_css.should == expected_result
expect(flipped_css).to eq(expected_result)
end

# background: #000 url("spree/frontend/cart.png") no-repeat left center;
Expand All @@ -71,7 +71,7 @@

flipped_css = r2.r2(css)

flipped_css.should == expected_result
expect(flipped_css).to eq(expected_result)
end


Expand All @@ -90,7 +90,7 @@

flipped_css = r2.r2(css)

flipped_css.should == expected_result
expect(flipped_css).to eq(expected_result)
end

it "handles newline correctly" do
Expand All @@ -105,174 +105,174 @@
'fieldset[disabled] .radio' +
'{cursor:not-allowed;}'

r2.r2(css).should == expected
expect(r2.r2(css)).to eq(expected)
end
end

describe "#declaration_swap" do
it "should handle nil" do
r2.declaration_swap(nil).should == ''
expect(r2.declaration_swap(nil)).to eq('')
end

it "should handle invalid declarations" do
r2.declaration_swap("not a decl").should == ''
expect(r2.declaration_swap("not a decl")).to eq('')
end

it "should swap a swappable parameter" do
r2.declaration_swap("padding-right:4px").should == 'padding-left:4px;'
expect(r2.declaration_swap("padding-right:4px")).to eq('padding-left:4px;')
end

it "should swap a swappable quad parameter" do
r2.declaration_swap("padding:1px 2px 3px 4px").should == 'padding:1px 4px 3px 2px;'
expect(r2.declaration_swap("padding:1px 2px 3px 4px")).to eq('padding:1px 4px 3px 2px;')
end

it "should ignore other parameters" do
r2.declaration_swap("foo:bar").should == 'foo:bar;'
expect(r2.declaration_swap("foo:bar")).to eq('foo:bar;')
end
end

describe "#minimize" do
it "should handle nil" do
r2.minimize(nil).should == ""
expect(r2.minimize(nil)).to eq("")
end

it "should strip comments" do
r2.minimize("/* comment */foo").should == "foo"
expect(r2.minimize("/* comment */foo")).to eq("foo")
end

it "should convert newlines to spaces" do
r2.minimize("foo\nbar").should == "foo bar"
expect(r2.minimize("foo\nbar")).to eq("foo bar")
end

it "should convert multiple newlines to a space" do
r2.minimize("foo\n\n\nbar").should == "foo bar"
expect(r2.minimize("foo\n\n\nbar")).to eq("foo bar")
end

it "should convert carriage returns to spaces" do
r2.minimize("foo\rbar").should == "foo bar"
expect(r2.minimize("foo\rbar")).to eq("foo bar")
end

it "should collapse multiple spaces into one" do
r2.minimize("foo bar").should == "foo bar"
expect(r2.minimize("foo bar")).to eq("foo bar")
end
end

describe "#direction_swap" do
it "should swap 'rtl' to 'ltr'" do
r2.direction_swap('rtl').should == 'ltr'
expect(r2.direction_swap('rtl')).to eq('ltr')
end

it "should swap 'ltr' to 'rtl'" do
r2.direction_swap('ltr').should == 'rtl'
expect(r2.direction_swap('ltr')).to eq('rtl')
end

it "should ignore values other than 'ltr' and 'rtl'" do
[nil, '', 'foo'].each do |val|
r2.direction_swap(val).should == val
expect(r2.direction_swap(val)).to eq(val)
end
end
end

describe "#side_swap" do
it "should swap 'right' to 'left'" do
r2.side_swap('right').should == 'left'
expect(r2.side_swap('right')).to eq('left')
end

it "should swap 'left' to 'right'" do
r2.side_swap('left').should == 'right'
expect(r2.side_swap('left')).to eq('right')
end

it "should ignore values other than 'left' and 'right'" do
[nil, '', 'foo'].each do |val|
r2.side_swap(val).should == val
expect(r2.side_swap(val)).to eq(val)
end
end
end

describe "#quad_swap" do
it "should swap a valid quad value" do
r2.quad_swap("1px 2px 3px 4px").should == "1px 4px 3px 2px"
expect(r2.quad_swap("1px 2px 3px 4px")).to eq("1px 4px 3px 2px")
end

it "should skip a pair value" do
r2.quad_swap("1px 2px").should == "1px 2px"
expect(r2.quad_swap("1px 2px")).to eq("1px 2px")
end
end

describe "#shadow_swap" do
it "should swap a 2 arg value" do
r2.shadow_swap("1px 2px").should == "-1px 2px"
expect(r2.shadow_swap("1px 2px")).to eq("-1px 2px")
end

it "should swap a 2 arg value from rtl to ltr" do
r2.shadow_swap("-1px 2px").should == "1px 2px"
expect(r2.shadow_swap("-1px 2px")).to eq("1px 2px")
end

it "should swap a 3 arg value" do
r2.shadow_swap("1px 2px #000").should == "-1px 2px #000"
expect(r2.shadow_swap("1px 2px #000")).to eq("-1px 2px #000")
end

it "should swap a 4 arg value" do
r2.shadow_swap("1px 2px 3px 4px").should == "-1px 2px 3px 4px"
expect(r2.shadow_swap("1px 2px 3px 4px")).to eq("-1px 2px 3px 4px")
end

it "should swap a 5 arg value" do
r2.shadow_swap("1px 2px 3px 4px #000").should == "-1px 2px 3px 4px #000"
expect(r2.shadow_swap("1px 2px 3px 4px #000")).to eq("-1px 2px 3px 4px #000")
end

it "should swap a 6 arg value" do
r2.shadow_swap("1px 2px 3px 4px #000 inset").should == "-1px 2px 3px 4px #000 inset"
expect(r2.shadow_swap("1px 2px 3px 4px #000 inset")).to eq("-1px 2px 3px 4px #000 inset")
end

it "should swap value starting with inset" do
r2.shadow_swap("inset 1px 2px").should == "-1px 2px inset"
expect(r2.shadow_swap("inset 1px 2px")).to eq("-1px 2px inset")
end

it "should swap multiple values" do
r2.shadow_swap("inset 1px 2px, 1px 2px #000").should == "-1px 2px inset, -1px 2px #000"
expect(r2.shadow_swap("inset 1px 2px, 1px 2px #000")).to eq("-1px 2px inset, -1px 2px #000")
end

it "should swap multiple values (with rgba)" do
r2.shadow_swap("inset 1px 2px rgba(0,0,0,0.2), 1px 2px #000").should == "-1px 2px rgba(0,0,0,0.2) inset, -1px 2px #000"
expect(r2.shadow_swap("inset 1px 2px rgba(0,0,0,0.2), 1px 2px #000")).to eq("-1px 2px rgba(0,0,0,0.2) inset, -1px 2px #000")
end

end

describe "#border_radius_swap" do
it "should swap a valid quad value" do
r2.border_radius_swap("1px 2px 3px 4px").should == "2px 1px 4px 3px"
expect(r2.border_radius_swap("1px 2px 3px 4px")).to eq("2px 1px 4px 3px")
end

it "should skip a triple value" do
r2.border_radius_swap("1px 2px 3px").should == "2px 1px 2px 3px"
expect(r2.border_radius_swap("1px 2px 3px")).to eq("2px 1px 2px 3px")
end

it "should skip a pair value" do
r2.border_radius_swap("1px 2px").should == "2px 1px"
expect(r2.border_radius_swap("1px 2px")).to eq("2px 1px")
end
end

describe "#background_position_swap" do

context "with a single value" do
it "should ignore a named-vertical" do
r2.background_position_swap('top').should == 'top'
expect(r2.background_position_swap('top')).to eq('top')
end

it "should swap a named-horizontal 'left'" do
r2.background_position_swap('left').should == 'right'
expect(r2.background_position_swap('left')).to eq('right')
end

it "should swap a named-horizontal 'right'" do
r2.background_position_swap('right').should == 'left'
expect(r2.background_position_swap('right')).to eq('left')
end

it "should invert a percentage" do
r2.background_position_swap('25%').should == '75%'
expect(r2.background_position_swap('25%')).to eq('75%')
end

it "should convert a unit value" do
r2.background_position_swap('25px').should == 'right 25px center'
expect(r2.background_position_swap('25px')).to eq('right 25px center')
end
end

Expand All @@ -283,35 +283,35 @@
# See: http://dev.w3.org/csswg/css3-background/#background-position

it "should swap named-horizontal and ignore named-vertical" do
r2.background_position_swap('right bottom').should == 'left bottom'
expect(r2.background_position_swap('right bottom')).to eq('left bottom')
end

it "should swap named-horizontal and ignore unit-vertical" do
r2.background_position_swap('left 100px').should == 'right 100px'
expect(r2.background_position_swap('left 100px')).to eq('right 100px')
end

it "should convert unit-horizontal" do
r2.background_position_swap('100px center').should == 'right 100px center'
expect(r2.background_position_swap('100px center')).to eq('right 100px center')
end

it "should swap named-horizontal and ignore percentage-vertical" do
r2.background_position_swap('left 0%').should == 'right 0%'
expect(r2.background_position_swap('left 0%')).to eq('right 0%')
end

it "should invert first percentage-horizontal value in a pair" do
r2.background_position_swap('25% 100%').should == '75% 100%'
expect(r2.background_position_swap('25% 100%')).to eq('75% 100%')
end
end

context "with a triplet of values" do
it "should swap named-horizontal" do
r2.background_position_swap('left 20px center').should == 'right 20px center'
expect(r2.background_position_swap('left 20px center')).to eq('right 20px center')
end
end

context "with a quad of values" do
it "should swap named-horizontal value" do
r2.background_position_swap('bottom 10px left 20px').should == 'bottom 10px right 20px'
expect(r2.background_position_swap('bottom 10px left 20px')).to eq('bottom 10px right 20px')
end
end
end
Expand Down

0 comments on commit 3a99799

Please sign in to comment.