diff --git a/README.md b/README.md index c6889d2..595771d 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,4 @@ The browser extension will also highlight the newly covered lines in `foo_bar.rb 2. Commit to `demo-branch`. You should now see duplication issues reported by Code Climate. + diff --git a/foo_bar.rb b/foo_bar.rb index bc32445..168d669 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/spec/foo_bar_spec.rb b/spec/foo_bar_spec.rb index 7689240..b2b3a0b 100644 --- a/spec/foo_bar_spec.rb +++ b/spec/foo_bar_spec.rb @@ -1,4 +1,27 @@ require "spec_helper" require_relative "../foo_bar" -# TODO: Add FooBar specs +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