Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improves code consistency
  • Loading branch information
brunohenrique committed Jan 31, 2015
commit 73aa29797b84f74b7f28be757318031673ec2f0e
12 changes: 6 additions & 6 deletions spec/bcrypt/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
end

specify "should produce random data" do
expect(BCrypt::Engine.generate_salt).not_to equal(BCrypt::Engine.generate_salt)
expect(BCrypt::Engine.generate_salt).not_to eq(BCrypt::Engine.generate_salt)
end

specify "should raise a InvalidCostError if the cost parameter isn't numeric" do
Expand All @@ -30,9 +30,9 @@
describe "Autodetecting of salt cost" do

specify "should work" do
expect(BCrypt::Engine.autodetect_cost("$2a$08$hRx2IVeHNsTSYYtUWn61Ou")).to eq 8
expect(BCrypt::Engine.autodetect_cost("$2a$05$XKd1bMnLgUnc87qvbAaCUu")).to eq 5
expect(BCrypt::Engine.autodetect_cost("$2a$13$Lni.CZ6z5A7344POTFBBV.")).to eq 13
expect(BCrypt::Engine.autodetect_cost("$2a$08$hRx2IVeHNsTSYYtUWn61Ou")).to eq(8)
expect(BCrypt::Engine.autodetect_cost("$2a$05$XKd1bMnLgUnc87qvbAaCUu")).to eq(5)
expect(BCrypt::Engine.autodetect_cost("$2a$13$Lni.CZ6z5A7344POTFBBV.")).to eq(13)
end

end
Expand Down Expand Up @@ -61,7 +61,7 @@ class MyInvalidSecret
end

specify "should call #to_s on the secret and use the return value as the actual secret data" do
expect(BCrypt::Engine.hash_secret(false, salt)).to eq BCrypt::Engine.hash_secret("false", salt)
expect(BCrypt::Engine.hash_secret(false, salt)).to eq(BCrypt::Engine.hash_secret("false", salt))
end

specify "should be interoperable with other implementations" do
Expand All @@ -74,7 +74,7 @@ class MyInvalidSecret
["0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "$2a$05$abcdefghijklmnopqrstuu", "$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui"]
]
for secret, salt, test_vector in test_vectors
expect(BCrypt::Engine.hash_secret(secret, salt)).to eql(test_vector)
expect(BCrypt::Engine.hash_secret(secret, salt)).to eq(test_vector)
end
end
end
24 changes: 12 additions & 12 deletions spec/bcrypt/password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@
end

specify "the cost should be set to the default if nil" do
expect(BCrypt::Password.create("hello", :cost => nil).cost).to equal(BCrypt::Engine::DEFAULT_COST)
expect(BCrypt::Password.create("hello", :cost => nil).cost).to eq(BCrypt::Engine::DEFAULT_COST)
end

specify "the cost should be set to the default if empty hash" do
expect(BCrypt::Password.create("hello", {}).cost).to equal(BCrypt::Engine::DEFAULT_COST)
expect(BCrypt::Password.create("hello", {}).cost).to eq(BCrypt::Engine::DEFAULT_COST)
end

specify "the cost should be set to the passed value if provided" do
expect(BCrypt::Password.create("hello", :cost => 5).cost).to equal(5)
expect(BCrypt::Password.create("hello", :cost => 5).cost).to eq(5)
end

specify "the cost should be set to the global value if set" do
BCrypt::Engine.cost = 5
expect(BCrypt::Password.create("hello").cost).to equal(5)
expect(BCrypt::Password.create("hello").cost).to eq(5)
# unset the global value to not affect other tests
BCrypt::Engine.cost = nil
end
Expand All @@ -61,7 +61,7 @@
old_default_cost = BCrypt::Engine::DEFAULT_COST

BCrypt::Engine::DEFAULT_COST = 5
expect(BCrypt::Password.create("hello").cost).to equal(5)
expect(BCrypt::Password.create("hello").cost).to eq(5)

# reset default to not affect other tests
BCrypt::Engine::DEFAULT_COST = old_default_cost
Expand All @@ -70,14 +70,14 @@

specify "should read the version, cost, salt, and hash" do
password = BCrypt::Password.new(hash)
expect(password.version).to eql("2a")
expect(password.version.class).to eq String
expect(password.cost).to equal(5)
expect(password.salt).to eql("$2a$05$CCCCCCCCCCCCCCCCCCCCC.")
expect(password.salt.class).to eq String
expect(password.version).to eq("2a")
expect(password.version.class).to eq(String)
expect(password.cost).to eq(5)
expect(password.salt).to eq("$2a$05$CCCCCCCCCCCCCCCCCCCCC.")
expect(password.salt.class).to eq(String)
expect(password.checksum).to eq("E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW")
expect(password.checksum.class).to eq String
expect(password.to_s).to eql(hash)
expect(password.checksum.class).to eq(String)
expect(password.to_s).to eq(hash)
end

specify "should raise an InvalidHashError when given an invalid hash" do
Expand Down