diff options
| author | Mario Visic <[email protected]> | 2018-12-27 21:30:58 +0800 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2019-01-03 20:15:29 -0800 |
| commit | 3ef35cdf4fd699cce93a51b1167d765324a213bd (patch) | |
| tree | f2e6aa3a950b0e1e36cd30ea20780c886b906be6 /test | |
| parent | ddc3d31a09557d4d24068078e9d4011df260dc93 (diff) | |
| download | ruby2d-3ef35cdf4fd699cce93a51b1167d765324a213bd.tar.gz ruby2d-3ef35cdf4fd699cce93a51b1167d765324a213bd.zip | |
Allow color to initialize from an existing color object
Setting a 2d object's color to be random is great, however it's difficult to
re-use that color without manually extracting out the rgba values from that
color object. Ideally it would be convenient to be able to do this:
```ruby
square = Square.new(color: 'random')
square_two = Square.new(color: square.color)
```
This patch allows this behavior from any 2d shape, making it much easier to
reuse those random colors :)
Diffstat (limited to 'test')
| -rw-r--r-- | test/color_spec.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/color_spec.rb b/test/color_spec.rb index 4f0ec35..e22c2c5 100644 --- a/test/color_spec.rb +++ b/test/color_spec.rb @@ -24,6 +24,17 @@ RSpec.describe Ruby2D::Color do it "raises error on bad color" do expect { Ruby2D::Color.new 42 }.to raise_error Ruby2D::Error end + + it "accepts an existing color object" do + expect { Ruby2D::Color.new(Ruby2D::Color.new('red')) }.to_not raise_error Ruby2D::Error + end + + it "assigns rgba from an existing color" do + c1 = Ruby2D::Color.new([20, 60, 80, 100]) + c2 = Ruby2D::Color.new(c1) + + expect([c2.r, c2.g, c2.b, c2.a]).to eq([20, 60, 80, 100]) + end end describe "#opacity" do |
