From 87b9962a8db81e3b196a64967150f538b43811ff Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Tue, 23 Feb 2016 23:04:43 +0100 Subject: [PATCH 1/2] Refactoring: introduce local, return early - use #reject - add basic spec around it --- .../generator/generator_processor.rb | 11 +++++------ spec/unit/generator/generator_processor_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 spec/unit/generator/generator_processor_spec.rb diff --git a/lib/github_changelog_generator/generator/generator_processor.rb b/lib/github_changelog_generator/generator/generator_processor.rb index 1791711..7350791 100644 --- a/lib/github_changelog_generator/generator/generator_processor.rb +++ b/lib/github_changelog_generator/generator/generator_processor.rb @@ -4,13 +4,12 @@ module GitHubChangelogGenerator # @param [Array] issues # @return [Array] filtered array def exclude_issues_by_labels(issues) - unless @options[:exclude_labels].nil? - issues = issues.select do |issue| - var = issue.labels.map(&:name) & @options[:exclude_labels] - !var.any? - end + return issues if !@options[:exclude_labels] || @options[:exclude_labels].empty? + + issues.reject do |issue| + labels = issue.labels.map(&:name) + (labels & @options[:exclude_labels]).any? end - issues end # @return [Array] filtered issues accourding milestone diff --git a/spec/unit/generator/generator_processor_spec.rb b/spec/unit/generator/generator_processor_spec.rb new file mode 100644 index 0000000..f127b7c --- /dev/null +++ b/spec/unit/generator/generator_processor_spec.rb @@ -0,0 +1,16 @@ +module GitHubChangelogGenerator + describe Generator do + context "#exclude_issues_by_labels" do + let(:label) { double("the-bad-label", name: "BAD") } + let(:issue) { double("the-issue-to-be-excluded", labels: [label]) } + let(:issues) { [issue] } + subject(:generator) { described_class.new(exclude_labels: %w(BAD BOO))} + + it "removes issues with labels in the exclude_label list" do + result = generator.exclude_issues_by_labels(issues) + + expect(result).to be_empty + end + end + end +end From 89d1b5393da20d963249667859b70f56458b5ea5 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Tue, 23 Feb 2016 23:23:54 +0100 Subject: [PATCH 2/2] Generator#exclude_issues_by_labels spec clearer --- .../unit/generator/generator_processor_spec.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/spec/unit/generator/generator_processor_spec.rb b/spec/unit/generator/generator_processor_spec.rb index f127b7c..be08d78 100644 --- a/spec/unit/generator/generator_processor_spec.rb +++ b/spec/unit/generator/generator_processor_spec.rb @@ -1,15 +1,27 @@ module GitHubChangelogGenerator describe Generator do context "#exclude_issues_by_labels" do - let(:label) { double("the-bad-label", name: "BAD") } + let(:label) { double("the-bad-label", name: "BAD") } let(:issue) { double("the-issue-to-be-excluded", labels: [label]) } - let(:issues) { [issue] } + let(:good_label) { double("a-good-label", name: "GOOD") } + let(:good_issue) { double("an-issue-to-be-kept", labels: [good_label]) } + let(:issues) { [issue, good_issue] } subject(:generator) { described_class.new(exclude_labels: %w(BAD BOO))} it "removes issues with labels in the exclude_label list" do result = generator.exclude_issues_by_labels(issues) - expect(result).to be_empty + expect(result).to include(good_issue) + expect(result).not_to include(issue) + end + + context "with no option given" do + subject(:generator) { described_class.new } + it "passes everything through when no option given" do + result = generator.exclude_issues_by_labels(issues) + + expect(result).to eq(issues) + end end end end