spec/unit/secretkey_spec.rb in secretkey-1.0.0 vs spec/unit/secretkey_spec.rb in secretkey-1.1.0

- old
+ new

@@ -2,25 +2,38 @@ describe SecretKey::SecretKey do let!(:key) { Faker::Number.number(15) } let!(:secret) { Faker::Bitcoin.address } - let!(:test_timestamp) { Time.new(2014, 07, 24, 12, 53).to_i } - let!(:generated_token) { Digest::SHA1.hexdigest("#{key}:#{secret}:#{test_timestamp}") } - describe '.generate_token' do - context 'when timestamp is valid' do - let!(:timestamp) { Time.new(2014, 07, 24, 12, 53).to_i } - it 'produces a token' do - expect(described_class.generate_token(key, secret, timestamp)).to eq(generated_token) + describe '#token' do + context 'when timestamp is not provided' do + let(:secret_key) { described_class.new(key, secret) } + let(:timestamp) { secret_key.timestamp } + let(:expected_token) { Digest::SHA1.hexdigest("#{key}:#{secret}:#{timestamp}") } + it 'produces a valid token' do + expect(secret_key.token).to eq(expected_token) end end - context 'when timestamp is invalid' do - let!(:timestamp) { 'sometext' } - it 'raises an invalid timestamp error' do - expect(lambda { described_class.generate_token(key, secret, timestamp) }).to raise_error(ArgumentError, 'Time Stamp is not a valid integer.') + context 'when timestamp is provided' do + let(:secret_key) { described_class.new(key, secret, timestamp: timestamp) } + + context 'when timestamp provided is valid' do + let(:timestamp) { Time.new(2014, 07, 24, 16, 54, 00).to_i } + let(:expected_token) { Digest::SHA1.hexdigest("#{key}:#{secret}:#{timestamp}") } + + it 'produces a valid token' do + expect(secret_key.token).to eq(expected_token) + end end + + context 'when timestamp is invalid' do + let(:timestamp) { 'askdfjlakshfdkjasd' } + + it 'produces an Argument Error' do + expect(lambda { secret_key.token }).to raise_error(ArgumentError, 'Time Stamp is not a valid integer.') + end + end end end - end \ No newline at end of file