Failed spec ran at: 
                                                                                                                                  
  1) Explo.generate_embed_token with other unknown errors raises TokenGenerationError for unexpected failure
     Failure/Error: expect { subject }.to raise_error(Explo::TokenGenerationError, /Unexpected failure/)
     
       expected Explo::TokenGenerationError with message matching /Unexpected failure/, got #<Explo::TokenGenerationError: JWT encryption failed: Boom> with backtrace:
         # ./lib/explo.rb:26:in `rescue in generate_embed_token'
         # ./lib/explo.rb:13:in `generate_embed_token'
         # ./spec/lib/explo_spec.rb:16:in `block (3 levels) in <top (required)>'
         # ./spec/lib/explo_spec.rb:82:in `block (5 levels) in <top (required)>'
         # ./spec/lib/explo_spec.rb:82:in `block (4 levels) in <top (required)>'
         # /Users/jrni/.rvm/gems/ruby-2.3.3@jrni/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
     # ./spec/lib/explo_spec.rb:82:in `block (4 levels) in <top (required)>'
     # /Users/jrni/.rvm/gems/ruby-2.3.3@jrni/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'

/Users/jrni/bookingbug/lib/explo.rb:25: warning: toplevel constant Exception referenced by JSON::JWE::Exception  |  ETA: 00:00:07 
Failed spec ran at: 
                                                                                                                                  
  2) Explo.generate_embed_token when secret key is missing raises ConfigurationError
     Failure/Error:
       expect {
         described_class.generate_embed_token(
           customer_id: customer_id,
           embed_id: embed_id,
           analytics_role: analytics_role
         )
       }.to raise_error(Explo::ConfigurationError, /secret_key_value/)
     
       expected Explo::ConfigurationError with message matching /secret_key_value/, got #<Explo::TokenGenerationError: JWT encryption failed: Explo configuration missing: 'embed_issuer_url'> with backtrace:
         # ./lib/explo.rb:26:in `rescue in generate_embed_token'
         # ./lib/explo.rb:13:in `generate_embed_token'
         # ./spec/lib/explo_spec.rb:65:in `block (5 levels) in <top (required)>'
         # ./spec/lib/explo_spec.rb:64:in `block (4 levels) in <top (required)>'
         # /Users/jrni/.rvm/gems/ruby-2.3.3@jrni/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
     # ./spec/lib/explo_spec.rb:64:in `block (4 levels) in <top (required)>'
     # /Users/jrni/.rvm/gems/ruby-2.3.3@jrni/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'

/Users/jrni/bookingbug/lib/explo.rb:25: warning: toplevel constant Exception referenced by JSON::JWE::Exception  |  ETA: 00:00:03 
Failed spec ran at: 
                                                                                                                                  
  3) Explo.generate_embed_token with valid Plus role behaves like an encrypted JWT string returns an encrypted JWT string with 5 base64url segments
     Failure/Error: raise TokenGenerationError, "JWT encryption failed: #{e.message}"
     
     Explo::TokenGenerationError:
       JWT encryption failed: undefined local variable or method `secret_key_id' for Explo:Module
     Shared Example Group: "an encrypted JWT string" called from ./spec/lib/explo_spec.rb:27
     # ./lib/explo.rb:26:in `rescue in generate_embed_token'
     # ./lib/explo.rb:13:in `generate_embed_token'
     # ./spec/lib/explo_spec.rb:16:in `block (3 levels) in <top (required)>'
     # ./spec/lib/explo_spec.rb:6:in `block (3 levels) in <top (required)>'
     # /Users/jrni/.rvm/gems/ruby-2.3.3@jrni/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NameError:
     #   undefined local variable or method `secret_key_id' for Explo:Module
     #   ./lib/explo.rb:22:in `generate_embed_token'

Failed spec ran at:  30 ==============>                                                                          |  ETA: 00:00:02 
                                                                                                                                  
  4) Explo.generate_embed_token when encryption fails raises TokenGenerationError with encryption message
     Failure/Error: allow(JSON::JWE).to receive(:encrypt).and_raise(JSON::JWE::EncryptionFailed.new("bad key"))
     
     NameError:
       uninitialized constant JSON::JWE::EncryptionFailed
     # ./spec/lib/explo_spec.rb:48:in `block (4 levels) in <top (required)>'
     # /Users/jrni/.rvm/gems/ruby-2.3.3@jrni/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'

/Users/jrni/bookingbug/lib/explo.rb:25: warning: toplevel constant Exception referenced by JSON::JWE::Exception  |  ETA: 00:00:01 
Failed spec ran at: 
                                                                                                                                  
  5) Explo.generate_embed_token with valid Essentials role behaves like an encrypted JWT string returns an encrypted JWT string with 5 base64url segments
     Failure/Error: raise TokenGenerationError, "JWT encryption failed: #{e.message}"
     
     Explo::TokenGenerationError:
       JWT encryption failed: undefined local variable or method `secret_key_id' for Explo:Module
     Shared Example Group: "an encrypted JWT string" called from ./spec/lib/explo_spec.rb:33
     # ./lib/explo.rb:26:in `rescue in generate_embed_token'
     # ./lib/explo.rb:13:in `generate_embed_token'
     # ./spec/lib/explo_spec.rb:16:in `block (3 levels) in <top (required)>'
     # ./spec/lib/explo_spec.rb:6:in `block (3 levels) in <top (required)>'
     # /Users/jrni/.rvm/gems/ruby-2.3.3@jrni/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NameError:
     #   undefined local variable or method `secret_key_id' for Explo:Module
     #   ./lib/explo.rb:22:in `generate_embed_token'

/Users/jrni/bookingbug/lib/explo.rb:25: warning: toplevel constant Exception referenced by JSON::JWE::Exception  |  ETA: 00:00:01 
Failed spec ran at: =========================== 80 ========================================>                     |  ETA: 00:00:00 
                                                                                                                                  
  6) Explo#get_available_embeds when ShardSetting lookup raises an error rescues the error and returns only the global embeds
     Failure/Error: customer_embeds = ShardSetting["explo_custom_embeds"] || []
     
     StandardError:
       database timeout
     # ./lib/explo.rb:33:in `get_available_embeds'
     # ./spec/lib/explo_spec.rb:118:in `block (4 levels) in <top (required)>'
     # /Users/jrni/.rvm/gems/ruby-2.3.3@jrni/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'

 10/10 |================================================= 100 ==================================================>| Time: 00:00:00 

above errors are coming for below rspecs:
# frozen_string_literal: true

describe Explo do
  shared_examples 'an encrypted JWT string' do
    it 'returns an encrypted JWT string with 5 base64url segments' do
      expect(subject).to match(/\A(?:[A-Za-z0-9_-]+\.){4}[A-Za-z0-9_-]+\z/)
    end
  end

  describe '.generate_embed_token' do
    let(:customer_id) { 'customer_123' }
    let(:embed_id) { 'embed_abc' }
    let(:expiration) { 1.hour.to_i }

    subject do
      described_class.generate_embed_token(
        customer_id: customer_id,
        embed_id: embed_id,
        analytics_role: analytics_role,
        expiration: expiration
      )
    end

    context 'with valid Plus role' do
      let(:analytics_role) { 'Plus' }

      it_behaves_like 'an encrypted JWT string'
    end

    context 'with valid Essentials role' do
      let(:analytics_role) { 'Essentials' }

      it_behaves_like 'an encrypted JWT string'
    end

    context 'with invalid role' do
      let(:analytics_role) { 'Basic' }

      it 'raises TokenGenerationError' do
        expect { subject }.to raise_error(Explo::TokenGenerationError, /Invalid analytics role/)
      end
    end

    context 'when encryption fails' do
      let(:analytics_role) { 'Plus' }

      before do
        allow(JSON::JWE).to receive(:encrypt).and_raise(JSON::JWE::EncryptionFailed.new("bad key"))
      end

      it 'raises TokenGenerationError with encryption message' do
        expect { subject }.to raise_error(Explo::TokenGenerationError, /JWT encryption failed/)
      end
    end

    context 'when secret key is missing' do
      let(:analytics_role) { 'Plus' }

      before do
        stub_const("LOCAL_SETTINGS", { 'explo' => { 'secret_key_id' => 'abc' } })
      end

      it 'raises ConfigurationError' do
        expect {
          described_class.generate_embed_token(
            customer_id: customer_id,
            embed_id: embed_id,
            analytics_role: analytics_role
          )
        }.to raise_error(Explo::ConfigurationError, /secret_key_value/)
      end
    end

    context 'with other unknown errors' do
      let(:analytics_role) { 'Plus' }

      before do
        allow(described_class).to receive(:get_permissions_for_role).and_raise("Boom")
      end

      it 'raises TokenGenerationError for unexpected failure' do
        expect { subject }.to raise_error(Explo::TokenGenerationError, /Unexpected failure/)
      end
    end
  end

  describe '#get_available_embeds' do
    context 'when customer has no specific embeds' do
      it 'returns only the global default embeds' do
        allow(ShardSetting).to receive(:[]).with("explo_custom_embeds").and_return(nil)
        embeds = described_class.get_available_embeds
        expect(embeds.map {|e| e['id'] }).to eq(['global_1', 'global_2'])
      end
    end

    context 'when customer has specific embeds' do
      let(:customer_embeds) { [{'id' => 'customer_1', 'name' => 'Customer Dashboard'}] }
      it 'returns a combination of global and customer embeds' do
        allow(ShardSetting).to receive(:[]).with("explo_custom_embeds").and_return(customer_embeds)
        embeds = described_class.get_available_embeds
        expect(embeds.map {|e| e['id'] }).to contain_exactly('global_1', 'global_2', 'customer_1')
      end
    end

    context 'when a customer embed has the same ID as a global embed' do
      let(:customer_embeds) { [{'id' => 'global_1', 'name' => 'Custom Version of Global 1'}] }
      it 'returns a unique list, preferring the first one found (global)' do
        allow(ShardSetting).to receive(:[]).with("explo_custom_embeds").and_return(customer_embeds)
        embeds = described_class.get_available_embeds
        expect(embeds.map {|e| e['id'] }).to contain_exactly('global_1', 'global_2')
        expect(embeds.find {|e| e['id'] == 'global_1' }['name']).to eq('Global Dashboard 1')
      end
    end

    context 'when ShardSetting lookup raises an error' do
      it 'rescues the error and returns only the global embeds' do
        allow(ShardSetting).to receive(:[]).with("explo_custom_embeds").and_raise(StandardError, "database timeout")
        embeds = described_class.get_available_embeds

        expect(embeds.map {|e| e['id'] }).to eq(['global_1', 'global_2'])
      end
    end
  end
end

For this code:
# frozen_string_literal: true

require 'json/jwt'

module Explo
  extend self

  class Error < StandardError; end
  class ConfigurationError < Error; end
  class TokenGenerationError < Error; end

  def generate_embed_token(customer_id:, embed_id:, analytics_role:, expiration: 24.hours.to_i)
    permissions = get_permissions_for_role(analytics_role)
    claims = {
      cst: customer_id.to_s,
      dsh: embed_id,
      exp: Time.now.to_i + expiration,
      iss: env!(:embed_issuer_url)
    }.merge(permissions)

    jwt = JSON::JWT.new(claims)
    jwt.header[:kid] = secret_key_id
    encrypted_jwt = jwt.encrypt(env!(:secret_key_value), 'dir', 'A256GCM')
    encrypted_jwt.to_s
  rescue JSON::JWE::Exception => e
    raise TokenGenerationError, "JWT encryption failed: #{e.message}"
  rescue StandardError => e
    raise TokenGenerationError, "Unexpected failure generating token: #{e.message}"
  end

  def get_available_embeds
    global_embeds = env!('default_embeds')
    customer_embeds = ShardSetting["explo_custom_embeds"] || []

    (global_embeds + customer_embeds).uniq {|embed| embed['id'] }
  end

  private

  def get_permissions_for_role(role_name)
    case role_name
    when 'Plus'
      {rbc: ['*'], des: false}
    when 'Essentials'
      {rbc: ['flt', 'srt', 'crt-view'], des: true}
    else
      raise TokenGenerationError, "Invalid analytics role for user: #{role_name.inspect}"
    end
  end

  def env!(name)
    value = LOCAL_SETTINGS.dig('explo', name.to_s)
    return value if !value.nil?

    raise ConfigurationError, "Explo configuration missing: '#{name}'"
  end
end


Can you give me complete rspecs fixed for this with exhaustive and all cases