let(:rsa_key){generate_key}let(:rsa_token){described_class.new(nil)}let(:rsa_encoded){rsa_token.encoded}before{allow_any_instance_of(described_class).toreceive(:key).and_return(rsa_key)}context'token'docontext'for valid key to be validated'dobefore{rsa_token['key']='value'}subject{JWT.decode(rsa_encoded,rsa_key)}it{expect{subject}.to_notraise_error}it{expect(subject.first).toinclude('key'=>'value')}endcontext'for invalid key to raise an exception'dolet(:new_key){generate_key}subject{JWT.decode(rsa_encoded,new_key)}it{expect{subject}.toraise_error(JWT::DecodeError)}endendprivatedefgenerate_keyOpenSSL::PKey::RSA.generate(512)endend