diff --git a/exe/gold_miner b/exe/gold_miner index 7141a69..d731e14 100755 --- a/exe/gold_miner +++ b/exe/gold_miner @@ -19,7 +19,8 @@ GoldMiner .fmap { |gold_container| debug "Found #{gold_container.gold_nuggets.size} messages in #{Time.now - t0} seconds." - puts GoldMiner.smith_blog_post(gold_container) + blog_post = GoldMiner.smith_blog_post(gold_container) + GoldMiner.distribute(blog_post) } .or { |error| abort "[ERROR] #{error}" } diff --git a/lib/gold_miner.rb b/lib/gold_miner.rb index b861346..88da9d6 100644 --- a/lib/gold_miner.rb +++ b/lib/gold_miner.rb @@ -20,6 +20,10 @@ def smith_blog_post(gold_container, ...) BlogPostSmith.new(...).smith(gold_container) end + def distribute(blog_post) + TerminalDistributor.new.distribute(blog_post) + end + private def prepare(slack_client) diff --git a/lib/gold_miner/terminal_distributor.rb b/lib/gold_miner/terminal_distributor.rb new file mode 100644 index 0000000..2c4f9a8 --- /dev/null +++ b/lib/gold_miner/terminal_distributor.rb @@ -0,0 +1,7 @@ +module GoldMiner + class TerminalDistributor + def distribute(blog_post) + puts blog_post + end + end +end diff --git a/spec/gold_miner/terminal_distributor_spec.rb b/spec/gold_miner/terminal_distributor_spec.rb new file mode 100644 index 0000000..84762d6 --- /dev/null +++ b/spec/gold_miner/terminal_distributor_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe GoldMiner::TerminalDistributor do + it_behaves_like "distributor" + + describe "#distribute" do + it "prints the blog post to STDOUT" do + blog_post = double("blog_post", to_s: "A blog post") + + expect { subject.distribute(blog_post) }.to output("A blog post\n").to_stdout + end + end +end diff --git a/spec/support/behaves_like_distributor.rb b/spec/support/behaves_like_distributor.rb new file mode 100644 index 0000000..0367198 --- /dev/null +++ b/spec/support/behaves_like_distributor.rb @@ -0,0 +1,3 @@ +RSpec.shared_examples "distributor" do + it { is_expected.to respond_to(:distribute) } +end