Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to comply with Standard linter
- Loading branch information
1 parent
45219b1
commit 4dd57b0
Showing
7 changed files
with
78 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module RubyIdenticon | ||
VERSION = '0.0.6' | ||
VERSION = "0.0.6" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,75 @@ | ||
require 'helper' | ||
require "helper" | ||
|
||
describe RubyIdenticon do | ||
before(:each) do | ||
Dir.mkdir('tmp') unless File.directory?('tmp') | ||
Dir.mkdir("tmp") unless File.directory?("tmp") | ||
end | ||
|
||
# general parameter tests | ||
it 'creates a binary string image blob' do | ||
expect(RubyIdenticon.create('RubyIdenticon')).to be_a_kind_of(String) | ||
it "creates a binary string image blob" do | ||
expect(RubyIdenticon.create("RubyIdenticon")).to be_a_kind_of(String) | ||
end | ||
|
||
it 'does not create a binary string image blob with an invalid title' do | ||
lambda { RubyIdenticon.create(nil) }.should raise_exception('title cannot be nil') | ||
it "does not create a binary string image blob with an invalid title" do | ||
lambda { RubyIdenticon.create(nil) }.should raise_exception("title cannot be nil") | ||
end | ||
|
||
it 'does not create a binary string image blob with an invalid key' do | ||
lambda { RubyIdenticon.create('identicons are great!', key: "\x00\x11\x22\x33\x44") }.should raise_exception('key is nil or less than 16 bytes') | ||
it "does not create a binary string image blob with an invalid key" do | ||
lambda { RubyIdenticon.create("identicons are great!", key: "\x00\x11\x22\x33\x44") }.should raise_exception("key is nil or less than 16 bytes") | ||
end | ||
|
||
it 'does not create a binary string image blob with an invalid grid size' do | ||
lambda { RubyIdenticon.create('RubyIdenticon', grid_size: 2) }.should raise_exception('grid_size must be between 4 and 9') | ||
lambda { RubyIdenticon.create('RubyIdenticon', grid_size: 20) }.should raise_exception('grid_size must be between 4 and 9') | ||
it "does not create a binary string image blob with an invalid grid size" do | ||
lambda { RubyIdenticon.create("RubyIdenticon", grid_size: 2) }.should raise_exception("grid_size must be between 4 and 9") | ||
lambda { RubyIdenticon.create("RubyIdenticon", grid_size: 20) }.should raise_exception("grid_size must be between 4 and 9") | ||
end | ||
|
||
it 'does not create a binary string image blob with an invalid square_size size' do | ||
lambda { RubyIdenticon.create('RubyIdenticon', square_size: -2) }.should raise_exception('invalid square size') | ||
it "does not create a binary string image blob with an invalid square_size size" do | ||
lambda { RubyIdenticon.create("RubyIdenticon", square_size: -2) }.should raise_exception("invalid square size") | ||
end | ||
|
||
it 'does not create a binary string image blob with an invalid border_size size' do | ||
lambda { RubyIdenticon.create('RubyIdenticon', border_size: -2) }.should raise_exception('invalid border size') | ||
it "does not create a binary string image blob with an invalid border_size size" do | ||
lambda { RubyIdenticon.create("RubyIdenticon", border_size: -2) }.should raise_exception("invalid border size") | ||
end | ||
|
||
# blob creation tests | ||
it 'creates a png image file' do | ||
blob = RubyIdenticon.create('RubyIdenticon') | ||
result = File.open('tmp/ruby_identicon.png', 'wb') { |f| f.write(blob) } | ||
it "creates a png image file" do | ||
blob = RubyIdenticon.create("RubyIdenticon") | ||
result = File.open("tmp/ruby_identicon.png", "wb") { |f| f.write(blob) } | ||
expect(result).to be_truthy | ||
end | ||
|
||
it 'creates a png image file of grid size 5, square size 70 and grey background' do | ||
blob = RubyIdenticon.create('RubyIdenticon', grid_size: 5, square_size: 70, background_color: 0xf0f0f0ff, key: '1234567890123456') | ||
result = File.open('tmp/ruby_identicon_gs5_white.png', 'wb') { |f| f.write(blob) } | ||
it "creates a png image file of grid size 5, square size 70 and grey background" do | ||
blob = RubyIdenticon.create("RubyIdenticon", grid_size: 5, square_size: 70, background_color: 0xf0f0f0ff, key: "1234567890123456") | ||
result = File.open("tmp/ruby_identicon_gs5_white.png", "wb") { |f| f.write(blob) } | ||
expect(result).to be_truthy | ||
end | ||
|
||
it 'creates 10 png image files' do | ||
it "creates 10 png image files" do | ||
10.times do |count| | ||
blob = RubyIdenticon.create("RubyIdenticon_#{count}") | ||
result = File.open("tmp/ruby_identicon_#{count}.png", 'wb') { |f| f.write(blob) } | ||
result = File.open("tmp/ruby_identicon_#{count}.png", "wb") { |f| f.write(blob) } | ||
expect(result).to be_truthy | ||
end | ||
end | ||
|
||
# file creation tests | ||
it 'creates a png image file via create_and_save' do | ||
result = RubyIdenticon.create_and_save('RubyIdenticon is fun', 'tmp/test_identicon.png') | ||
it "creates a png image file via create_and_save" do | ||
result = RubyIdenticon.create_and_save("RubyIdenticon is fun", "tmp/test_identicon.png") | ||
expect(result).to be_truthy | ||
end | ||
|
||
it 'does not create a png image file via create_and_save with an invalid filename' do | ||
lambda { RubyIdenticon.create_and_save('RubyIdenticon is fun', nil) }.should raise_exception('filename cannot be nil') | ||
it "does not create a png image file via create_and_save with an invalid filename" do | ||
lambda { RubyIdenticon.create_and_save("RubyIdenticon is fun", nil) }.should raise_exception("filename cannot be nil") | ||
end | ||
|
||
it 'does not create a png image file via create_and_save with an invalid title' do | ||
lambda { RubyIdenticon.create_and_save(nil, 'tmp/test_identicon.png') }.should raise_exception('title cannot be nil') | ||
it "does not create a png image file via create_and_save with an invalid title" do | ||
lambda { RubyIdenticon.create_and_save(nil, "tmp/test_identicon.png") }.should raise_exception("title cannot be nil") | ||
end | ||
|
||
# Base64 creation tests | ||
it 'creates base64 version of the image' do | ||
blob = RubyIdenticon.create('RubyIdenticon') | ||
base64 = RubyIdenticon.create_base64('RubyIdenticon') | ||
it "creates base64 version of the image" do | ||
blob = RubyIdenticon.create("RubyIdenticon") | ||
base64 = RubyIdenticon.create_base64("RubyIdenticon") | ||
expect(Base64.decode64(base64)).to eq blob | ||
end | ||
end |