Sha256: 1ccbf14a42d8352d22128d838cfb0b307f5f9e0b94c6fb9d48620d6c3c1cce30

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 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("Pushing 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,
                         :headers => {
                           'Authorization' => 'key', 
                           'Content-Type' => 'application/octet-stream', 
                           'User-Agent'=>'Nexus Gem Command'
                         })
        #assert_requested(:post, @url,
        #                 :headers => {'Content-Length' => @gem_binary.size.to_s})
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nexus-0.1.0 test/nexus_command_test.rb