|
8 | 8 | end |
9 | 9 |
|
10 | 10 | specify "should return a BCrypt::Password" do |
11 | | - @password.should be_an_instance_of(BCrypt::Password) |
| 11 | + expect(@password).to be_an_instance_of(BCrypt::Password) |
12 | 12 | end |
13 | 13 |
|
14 | 14 | specify "should return a valid bcrypt password" do |
15 | | - lambda { BCrypt::Password.new(@password) }.should_not raise_error |
| 15 | + expect { BCrypt::Password.new(@password) }.not_to raise_error |
16 | 16 | end |
17 | 17 |
|
18 | 18 | specify "should behave normally if the secret is not a string" do |
19 | | - lambda { BCrypt::Password.create(nil) }.should_not raise_error(BCrypt::Errors::InvalidSecret) |
20 | | - lambda { BCrypt::Password.create({:woo => "yeah"}) }.should_not raise_error(BCrypt::Errors::InvalidSecret) |
21 | | - lambda { BCrypt::Password.create(false) }.should_not raise_error(BCrypt::Errors::InvalidSecret) |
| 19 | + expect { BCrypt::Password.create(nil) }.not_to raise_error |
| 20 | + expect { BCrypt::Password.create({:woo => "yeah"}) }.not_to raise_error |
| 21 | + expect { BCrypt::Password.create(false) }.not_to raise_error |
22 | 22 | end |
23 | 23 |
|
24 | 24 | specify "should tolerate empty string secrets" do |
25 | | - lambda { BCrypt::Password.create( "\n".chop ) }.should_not raise_error |
26 | | - lambda { BCrypt::Password.create( "" ) }.should_not raise_error |
27 | | - lambda { BCrypt::Password.create( String.new ) }.should_not raise_error |
| 25 | + expect { BCrypt::Password.create( "\n".chop ) }.not_to raise_error |
| 26 | + expect { BCrypt::Password.create( "" ) }.not_to raise_error |
| 27 | + expect { BCrypt::Password.create( String.new ) }.not_to raise_error |
28 | 28 | end |
29 | 29 | end |
30 | 30 |
|
|
35 | 35 | end |
36 | 36 |
|
37 | 37 | specify "the cost is too damn high" do |
38 | | - lambda { |
| 38 | + expect { |
39 | 39 | BCrypt::Password.create("hello", :cost => 32) |
40 | | - }.should raise_error(ArgumentError) |
| 40 | + }.to raise_error(ArgumentError) |
41 | 41 | end |
42 | 42 |
|
43 | 43 | specify "the cost should be set to the default if nil" do |
44 | | - BCrypt::Password.create("hello", :cost => nil).cost.should equal(BCrypt::Engine::DEFAULT_COST) |
| 44 | + expect(BCrypt::Password.create("hello", :cost => nil).cost).to equal(BCrypt::Engine::DEFAULT_COST) |
45 | 45 | end |
46 | 46 |
|
47 | 47 | specify "the cost should be set to the default if empty hash" do |
48 | | - BCrypt::Password.create("hello", {}).cost.should equal(BCrypt::Engine::DEFAULT_COST) |
| 48 | + expect(BCrypt::Password.create("hello", {}).cost).to equal(BCrypt::Engine::DEFAULT_COST) |
49 | 49 | end |
50 | 50 |
|
51 | 51 | specify "the cost should be set to the passed value if provided" do |
52 | | - BCrypt::Password.create("hello", :cost => 5).cost.should equal(5) |
| 52 | + expect(BCrypt::Password.create("hello", :cost => 5).cost).to equal(5) |
53 | 53 | end |
54 | 54 |
|
55 | 55 | specify "the cost should be set to the global value if set" do |
56 | 56 | BCrypt::Engine.cost = 5 |
57 | | - BCrypt::Password.create("hello").cost.should equal(5) |
| 57 | + expect(BCrypt::Password.create("hello").cost).to equal(5) |
58 | 58 | # unset the global value to not affect other tests |
59 | 59 | BCrypt::Engine.cost = nil |
60 | 60 | end |
|
65 | 65 | old_default_cost = BCrypt::Engine::DEFAULT_COST |
66 | 66 |
|
67 | 67 | BCrypt::Engine::DEFAULT_COST = 5 |
68 | | - BCrypt::Password.create("hello").cost.should equal(5) |
| 68 | + expect(BCrypt::Password.create("hello").cost).to equal(5) |
69 | 69 |
|
70 | 70 | # reset default to not affect other tests |
71 | 71 | BCrypt::Engine::DEFAULT_COST = old_default_cost |
|
74 | 74 |
|
75 | 75 | specify "should read the version, cost, salt, and hash" do |
76 | 76 | password = BCrypt::Password.new(@hash) |
77 | | - password.version.should eql("2a") |
78 | | - password.cost.should equal(5) |
79 | | - password.salt.should eql("$2a$05$CCCCCCCCCCCCCCCCCCCCC.") |
80 | | - password.salt.class.should eq String |
81 | | - password.checksum.should eq("E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW") |
82 | | - password.checksum.class.should eq String |
83 | | - password.to_s.should eql(@hash) |
| 77 | + expect(password.version).to eql("2a") |
| 78 | + expect(password.cost).to equal(5) |
| 79 | + expect(password.salt).to eql("$2a$05$CCCCCCCCCCCCCCCCCCCCC.") |
| 80 | + expect(password.salt.class).to eq String |
| 81 | + expect(password.checksum).to eq("E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW") |
| 82 | + expect(password.checksum.class).to eq String |
| 83 | + expect(password.to_s).to eql(@hash) |
84 | 84 | end |
85 | 85 |
|
86 | 86 | specify "should raise an InvalidHashError when given an invalid hash" do |
87 | | - lambda { BCrypt::Password.new('weedle') }.should raise_error(BCrypt::Errors::InvalidHash) |
| 87 | + expect { BCrypt::Password.new('weedle') }.to raise_error(BCrypt::Errors::InvalidHash) |
88 | 88 | end |
89 | 89 | end |
90 | 90 |
|
|
96 | 96 | end |
97 | 97 |
|
98 | 98 | specify "should compare successfully to the original secret" do |
99 | | - (@password == @secret).should be(true) |
| 99 | + expect((@password == @secret)).to be(true) |
100 | 100 | end |
101 | 101 |
|
102 | 102 | specify "should compare unsuccessfully to anything besides original secret" do |
103 | | - (@password == "@secret").should be(false) |
| 103 | + expect((@password == "@secret")).to be(false) |
104 | 104 | end |
105 | 105 | end |
106 | 106 |
|
107 | 107 | describe "Validating a generated salt" do |
108 | 108 | specify "should not accept an invalid salt" do |
109 | | - BCrypt::Engine.valid_salt?("invalid").should eq(false) |
| 109 | + expect(BCrypt::Engine.valid_salt?("invalid")).to eq(false) |
110 | 110 | end |
111 | 111 | specify "should accept a valid salt" do |
112 | | - BCrypt::Engine.valid_salt?(BCrypt::Engine.generate_salt).should eq(true) |
| 112 | + expect(BCrypt::Engine.valid_salt?(BCrypt::Engine.generate_salt)).to eq(true) |
113 | 113 | end |
114 | 114 | end |
115 | 115 |
|
116 | 116 | describe "Validating a password hash" do |
117 | 117 | specify "should not accept an invalid password" do |
118 | | - BCrypt::Password.valid_hash?("i_am_so_not_valid").should be_false |
| 118 | + expect(BCrypt::Password.valid_hash?("i_am_so_not_valid")).to be_false |
119 | 119 | end |
120 | 120 | specify "should accept a valid password" do |
121 | | - BCrypt::Password.valid_hash?(BCrypt::Password.create "i_am_so_valid").should be_true |
| 121 | + expect(BCrypt::Password.valid_hash?(BCrypt::Password.create "i_am_so_valid")).to be_true |
122 | 122 | end |
123 | 123 | end |
0 commit comments