Sha256: 557ebc4f6cf0bf4e335af0eb6d89929deaa487cd34d65408016cbef451a7aa04

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

require 'command_helper'

class NexusCommandTest < CommandTest
  context "pushing" do
    setup do
      @command = Gem::Commands::NexusCommand.new
      stub(@command).say
    end

    should "setup and send the gem" do
      mock(@command).setup
      mock(@command).send_gem
      @command.execute
      assert_received(@command) { |command| command.setup }
      assert_received(@command) { |command| command.send_gem }
    end

    should "raise an error with no arguments" do
      assert_raise Gem::CommandLineError do
        @command.send_gem
      end
    end

    context "pushing a gem" do
      setup do

        @gem_path = "path/to/foo-0.0.0.gem"
        baseurl = 'http://localhost:8081/nexus/content/repositories/localgems'
        @url = baseurl + @gem_path.sub(/.*\//, '/gems/')
        @gem_binary = StringIO.new("gem")

        stub(@command).say
        stub(@command).options { {:args => [@gem_path]} }
        stub(Gem).read_binary(@gem_path) { @gem_binary }
        stub(@command).config { { :authorization => "key", :url => baseurl } }
        stub_request(:post, @url).to_return(:status => 201)
        
        @command.send_gem
      end

      should "say push was successful" do
        assert_received(@command) { |command| command.say("Uploading gem to Nexus...") }
        # due to webmock there is no status message
        assert_received(@command) { |command| command.say("") }
      end

      should "post to api" do
        # webmock doesn't pass body params on correctly :[
        assert_requested(:post, @url,
                         :times => 1)
        assert_requested(:post, @url,
                         :body => @gem_binary,
                         :headers => {
                           'Authorization' => 'key', 
                           'Content-Type' => 'application/octet-stream'
                         })
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nexus-1.1.0 test/nexus_command_test.rb
nexus-1.0.1 test/nexus_command_test.rb
nexus-1.0.0 test/nexus_command_test.rb