Sha256: 485e121969b508af62adc6ad30c5a1939f443081e907bdfbf18378564edba70e

Contents?: true

Size: 1.94 KB

Versions: 6

Compression:

Stored size: 1.94 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')

require 'tmpdir'
require 'fileutils'

describe ::Inch::CLI::Command::Diff do
  before do
    @command = ::Inch::CLI::Command::Diff
    @git_url = 'https://github.com/rrrene/sparkr.git'
    @git_dir = 'sparkr'
    @git_rev1 = '9da8aeaa64ff21daa1b39e3493134d42d67eb71a'
    @git_rev2 = 'HEAD'

    @tmp_dir = Dir.mktmpdir
    # clone the given repo to the tmp_dir
    Dir.chdir @tmp_dir
    `git clone #{@git_url} 2>&1`
    @cloned_dir = File.join(@tmp_dir, @git_dir)
    Dir.chdir @cloned_dir
  end

  after do
    FileUtils.rm_rf @tmp_dir
  end

  it 'should run with exit status' do
    _out, _err = capture_io do
      assert_equal @command.run.exit_status, @command::EXIT_STATUS_SUCCESS
    end
  end

  it 'should not show any changes' do
    # this runs `inch diff` on a freshly cloned repo
    # should not show any changes
    out, err = capture_io do
      @command.run
    end
    refute out.empty?, 'there should be some output'
    assert err.empty?, 'there should be no errors'
    assert_match(/\bno changes\b/i, out)

    # this runs `inch diff` on two distinct revisions
    # should show some changes
    out, err = capture_io do
      @command.run(@git_rev1, @git_rev2)
    end
    refute out.empty?, 'there should be some output'
    assert err.empty?, 'there should be no errors'
    assert_match(/\bshowing changes\b/i, out)

    # we now remove all comments in a single file
    filename = File.join(@cloned_dir, 'lib/sparkr.rb')
    content = File.read(filename)
    content_without_comments = content.gsub(/\s+#(.+)/, '')
    File.open(filename, 'w') { |f| f.write(content_without_comments) }

    # running the standard `inch diff` again
    # should now show some changes
    out, err = capture_io do
      @command.run
    end
    refute out.empty?, 'there should be some output'
    assert err.empty?, 'there should be no errors'
    assert_match(/\bshowing changes\b/i, out)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
inch-0.9.0.rc1 test/integration/cli/command/diff_test.rb
inch-0.8.0 test/integration/cli/command/diff_test.rb
inch-0.8.0.rc2 test/integration/cli/command/diff_test.rb
inch-0.8.0.rc1 test/integration/cli/command/diff_test.rb
inch-0.7.1 test/integration/cli/command/diff_test.rb
inch-0.7.0 test/integration/cli/command/diff_test.rb