Skip to content

Commit

Permalink
chore(ad lid): More tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Aug 10, 2018
1 parent cfc9ef4 commit f9c9840
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/fakerbot/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def list(*)
if options[:help]
invoke :help, ['list']
else
Fakerbot::Commands::List.new(options).execute
FakerBot::Commands::List.new(options).execute
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fakerbot/commands/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_relative '../command'

module Fakerbot
module FakerBot
module Commands
class List < FakerBot::Command
def initialize(options)
Expand Down
9 changes: 5 additions & 4 deletions lib/fakerbot/commands/search.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'fakerbot/bot'
require_relative '../command'

module FakerBot
module Commands
Expand All @@ -9,15 +10,15 @@ def initialize(options)
@options = options
end

def execute(input)
render FakerBot::Bot.find(input)
def execute(input, output: $stdout)
render FakerBot::Bot.find(input), output
end

private

def render(result)
def render(result, output)
return not_found if result.empty?
super
super(result, output)
end

def not_found
Expand Down
34 changes: 34 additions & 0 deletions spec/integration/search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

RSpec.describe '`fakerbot search` command', type: :cli do
it 'executes `fakerbot help search` command successfully' do
output = `fakerbot help search`
expected_output = <<~OUT
Usage:
fakerbot search [Faker]
Options:
-h, [--help], [--no-help] # Display usage information
-v, [--verbose], [--no-verbose] # Display Faker constants methods with examples
Search Faker method(s)
OUT

expect(output).to eq(expected_output)
end

context 'when search query exists' do
it 'returns results' do
output = `fakerbot search name`
expect(output).to match(/Faker::/)
expect(output).to match(/└──/)
end
end

context 'when search query does not exist' do
it 'returns a not found message' do
output = `fakerbot search asdasdhk`
expect(output).to match(/Sorry, we couldn't find a match/)
end
end
end
4 changes: 2 additions & 2 deletions spec/unit/list_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'fakerbot/commands/list'

RSpec.describe Fakerbot::Commands::List do
RSpec.describe FakerBot::Commands::List do
let(:output) { StringIO.new }
let(:options) { {} }
let(:command) { Fakerbot::Commands::List.new(options) }
let(:command) { FakerBot::Commands::List.new(options) }

before do
command.execute(output: output)
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'fakerbot/commands/search'

RSpec.describe FakerBot::Commands::Search do
let(:output) { StringIO.new }
let(:options) { {} }
let(:command) { described_class.new(options) }

context 'when query object exists' do
before do
command.execute('image', output: output)
end

it 'returns results' do
expect(output.string).to match(/Faker/)
expect(output.string.lines.size).to be_positive
end
end

context 'when query object does not exist' do
before do
command.execute('hasjdhaksjd', output: output)
end

it 'returns nil' do
expect(output.string).to be_empty
end
end
end

0 comments on commit f9c9840

Please sign in to comment.