diff --git a/Gemfile b/Gemfile index 80af9d8..101fc26 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -# frozen_string_literal: true +#frozen_string_literal: true source "https://rubygems.org" gem "codeclimate-test-reporter" diff --git a/README.md b/README.md index 4a54c89..8c2e8b1 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,16 @@ Code Climate Lunch & Learn Example Example files: https://gist.github.com/dblandin/589e70345774298e1622850349c31876 + +## Setup -## Setup 1. Install the Code Climate [browser extension](https://codeclimate.com/browser-extension) 1. [Fork](https://github.com/codeclimate-demo/example-foobar#fork-destination-box) this project -## Introduce some complexity +## Introduce some complexity 1. Modify `foo_bar.rb` with [this content](https://gist.github.com/dblandin/589e70345774298e1622850349c31876#file-foo_bar-rb) from gist 1. Push to fork and open PR against master @@ -62,6 +63,3 @@ You should now see green annotations which mean those lines are now covered by ``` You should now see duplication issues reported by Code Climate. - - - diff --git a/duplication_2.rb b/duplication_2.rb index debf01d..fb0f995 100644 --- a/duplication_2.rb +++ b/duplication_2.rb @@ -1 +1,30 @@ -# TODO: Add duplication_2.rb content +require "securerandom" + +module DuplicationExample + def identical(message, header: true) + body = [] + body << "-- HEADER --" if header + body << "-- MESSAGE --" + body << message + body << "-- FOOTER --" + message = body.join("\n") + + if message.length > 100 + message[0, 100] + else + message + end + end + + def similar + hex = SecureRandom.hex(20) + hex.reverse + hex += "-suffix" + + if hex.start_with?("z") + hex += "something-else" + end + + hex + end +end diff --git a/foo_bar.rb b/foo_bar.rb index bc32445..44c0eb1 100644 --- a/foo_bar.rb +++ b/foo_bar.rb @@ -1 +1,22 @@ -# TODO: Add FooBar content +class FooBar + def run(items = gets.chomp.to_i) + if items > 0 + list = [] + (1..items).each do |n| + if n % 3 == 0 && n % 5 == 0 + list << "FOOBAR" + elsif n % 3 == 0 + list << "FOO" + elsif n % 5 == 0 + list << "BAR" + else + list << n + end + end + else + puts "Please enter a positive number " + end + + list + end +end diff --git a/nestfolder1/nestfolder2/example.rb b/nestfolder1/nestfolder2/example.rb index 31bd03f..6e47d1a 100644 --- a/nestfolder1/nestfolder2/example.rb +++ b/nestfolder1/nestfolder2/example.rb @@ -145,4 +145,131 @@ test test test +testtest +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test test +test +test +test +test +test +test +test + +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +test +testtest +test +test +test +test +test +test +test +testtest +test +test +test +test +test +test +test +testtest +test +test +test +test +test +test +test +testtest +test +test + + diff --git a/spec/foo_bar_spec.rb b/spec/foo_bar_spec.rb index 7689240..587fb09 100644 --- a/spec/foo_bar_spec.rb +++ b/spec/foo_bar_spec.rb @@ -1,4 +1,30 @@ require "spec_helper" require_relative "../foo_bar" -# TODO: Add FooBar specs +require "spec_helper" +require_relative "../foo_bar" + +describe "FooBar" do + it "returns correct list of items" do + result = FooBar.new.run(15) + + expect(result.length).to eq(15) + expect(result).to eq([ + 1, + 2, + "FOO", + 4, + "BAR", + "FOO", + 7, + 8, + "FOO", + "BAR", + 11, + "FOO", + 13, + 14, + "FOOBAR", + ]) + end +end