Skip to content

Commit

Permalink
[Fixed] Testing dsl now correctly creates gem project
Browse files Browse the repository at this point in the history
An old feature test was being skipped as test behaviour and actual behaviour were differently for license_finder diff.
This behaviour was caused because during test, created a gem for a project was being overwritten by a gem for another
with same gem name, but different version.
Testing dsl now takes gem version into account upon creation to avoid unwanted deletion of gem

[#170772369]
  • Loading branch information
Pivotal-Jeff-Jun authored and Calgary committed Jan 22, 2020
1 parent 5d50e6a commit 6158d76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
11 changes: 4 additions & 7 deletions features/features/report/diff_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@

diff = IO.read(project.project_dir.join('diff.csv'))
expect(diff).to include("unchanged,bar,2.0.0,GPLv2,#{project1.project_dir}")
expect(diff).to include("removed,foo,1.0.0,MIT,\"#{project1.project_dir},#{project2.project_dir}\"")
expect(diff).to include("added,foo,2.0.0,BSD,\"#{project1.project_dir},#{project2.project_dir}\"")
expect(diff).to include("unchanged,foo,1.0.0,MIT,#{project2.project_dir}")
expect(diff).to include("added,foo,2.0.0,BSD,#{project1.project_dir}")
expect(diff).to include("added,baz,3.0.0,BSD,#{project2.project_dir}")
end

xspecify 'show licenses change when files do not contain exact copies of a dep' do
specify 'show licenses change when files do not contain exact copies of a dep' do
project = developer.create_empty_project
# First multi-project report
project1 = developer.create_ruby_app('project_1')
Expand All @@ -193,10 +193,7 @@

diff = IO.read(project.project_dir.join('diff.csv'))
expect(diff).to include("removed,foo,1.0.0,MIT,#{project1.project_dir}")
# expect(diff).to include("removed,foo,,2.0.0,BSD,#{project2.project_dir}")
expect(diff).to include("added,foo,2.0.0,BSD,\"#{project1.project_dir},#{project2.project_dir}\"")
expect(diff).to include("removed,foo,1.0.0,BSD,\"#{project1.project_dir},#{project2.project_dir}\"")

expect(diff).to include("unchanged,foo,2.0.0,BSD,\"#{project1.project_dir},#{project2.project_dir}\"")
expect(diff).to include("unchanged,bar,2.0.0,GPLv2,#{project1.project_dir}")
expect(diff).to include("added,baz,3.0.0,BSD,#{project2.project_dir}")
end
Expand Down
25 changes: 18 additions & 7 deletions features/support/testing_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def execute_command_in_path(command, path)
require 'forwardable'
class Project
extend Forwardable
def_delegators :project_dir, :shell_out, :add_to_file, :install_fixture
def_delegators :project_dir, :shell_out, :add_to_file, :remove_lines_with_value, :install_fixture

attr_reader :name

Expand Down Expand Up @@ -499,9 +499,14 @@ def depend_on(gem, bundler_options = {})
private

def add_gem_to_gemfile(gem_name, options)
remove_older_gem_from_gemfile(gem_name)
add_to_gemfile("gem #{gem_name.inspect}, #{options.inspect}")
end

def remove_older_gem_from_gemfile(gem_name)
remove_lines_with_value('Gemfile', gem_name)
end

def add_to_gemfile(content)
add_to_file('Gemfile', content)
end
Expand Down Expand Up @@ -533,7 +538,7 @@ def add_to_gemfile(content)
# lives adjacent to a BundlerProject, so has a different lifecycle from other Projects and doesn't inherit
class GemProject
def self.create(name, options)
result = new(name)
result = new(name, options[:version])
result.define(options)
result
end
Expand All @@ -544,23 +549,24 @@ def self.create_in_path(name, path, options)
result
end

def initialize(name, path = nil)
def initialize(name, version = nil, path = nil)
@name = name
@path = path
@file_name = version.nil? ? name : "#{name}-#{version}"
project_dir.make
end

def define(options)
project_dir.write_file("#{name}.gemspec", gemspec_string(options))
project_dir.write_file("#{file_name}.gemspec", gemspec_string(options))
end

attr_reader :name, :path
attr_reader :name, :path, :file_name

def project_dir
if path
Paths.project(path + '/' + name)
Paths.project(path + '/' + file_name)
else
Paths.project(name)
Paths.project(file_name)
end
end

Expand Down Expand Up @@ -634,6 +640,11 @@ def write_file(filename, content)
join(filename).open('w') { |file| file.write content }
end

def remove_lines_with_value(filename, value)
updated_content = join(filename).open('r').readlines.reject { |line| line.include?(value) }.join
write_file(filename, updated_content)
end

def install_fixture(fixture_name)
if RUBY_PLATFORM =~ /mswin|cygwin|mingw/
FileUtils.cp(Paths.fixtures.join(fixture_name), join(fixture_name))
Expand Down

0 comments on commit 6158d76

Please sign in to comment.