spec/slosilo_spec.rb in slosilo-1.0.0 vs spec/slosilo_spec.rb in slosilo-1.1.0

- old
+ new

@@ -5,36 +5,36 @@ include_context "with example key" before { Slosilo['test'] = key } describe '[]' do it "returns a Slosilo::Key" do - Slosilo[:test].should be_instance_of Slosilo::Key + expect(Slosilo[:test]).to be_instance_of Slosilo::Key end it "allows looking up by fingerprint" do - Slosilo[fingerprint: key_fingerprint].should == key + expect(Slosilo[fingerprint: key_fingerprint]).to eq(key) end context "when the requested key does not exist" do it "returns nil instead of creating a new key" do - Slosilo[:aether].should_not be + expect(Slosilo[:aether]).not_to be end end end describe '.sign' do let(:own_key) { double "own key" } - before { Slosilo.stub(:[]).with(:own).and_return own_key } + before { allow(Slosilo).to receive(:[]).with(:own).and_return own_key } let (:argument) { double "thing to sign" } it "fetches the own key and signs using that" do - own_key.should_receive(:sign).with(argument) + expect(own_key).to receive(:sign).with(argument) Slosilo.sign argument end end describe '.token_valid?' do - before { adapter['test'].stub token_valid?: false } + before { allow(adapter['test']).to receive_messages token_valid?: false } let(:key2) { double "key 2", token_valid?: false } let(:key3) { double "key 3", token_valid?: false } before do adapter[:key2] = key2 adapter[:key3] = key3 @@ -42,51 +42,51 @@ let(:token) { double "token" } subject { Slosilo.token_valid? token } context "when no key validates the token" do - before { Slosilo::Key.stub new: (double "key", token_valid?: false) } - it { should be_false } + before { allow(Slosilo::Key).to receive_messages new: (double "key", token_valid?: false) } + it { is_expected.to be_falsey } end context "when a key validates the token" do let(:valid_key) { double token_valid?: true } let(:invalid_key) { double token_valid?: true } before do - Slosilo::Key.stub new: invalid_key + allow(Slosilo::Key).to receive_messages new: invalid_key adapter[:key2] = valid_key end - it { should be_true } + it { is_expected.to be_truthy } end end describe '.token_signer' do context "when token matches a key" do let(:token) {{ 'data' => 'foo', 'key' => key.fingerprint, 'signature' => 'XXX' }} context "and the signature is valid" do - before { key.stub(:token_valid?).with(token).and_return true } + before { allow(key).to receive(:token_valid?).with(token).and_return true } it "returns the key id" do - subject.token_signer(token).should == 'test' + expect(subject.token_signer(token)).to eq('test') end end context "and the signature is invalid" do - before { key.stub(:token_valid?).with(token).and_return false } + before { allow(key).to receive(:token_valid?).with(token).and_return false } it "returns nil" do - subject.token_signer(token).should_not be + expect(subject.token_signer(token)).not_to be end end end context "when token doesn't match a key" do let(:token) {{ 'data' => 'foo', 'key' => "footprint", 'signature' => 'XXX' }} it "returns nil" do - subject.token_signer(token).should_not be + expect(subject.token_signer(token)).not_to be end end end end