Skip to content

Commit

Permalink
Refactored tests and fixed results.
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Jan 16, 2017
1 parent 0ebfecd commit f601075
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/lita/handlers/onewheel_duckduckgo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def search(response)
end

def get_result(query)
result = RestClient.get("http://api.duckduckgo.com/?q=#{query}&format=json")
JSON.parse(RestClient.get("http://api.duckduckgo.com/?q=#{query}&format=json"))
end

Lita.register_handler(self)
Expand Down
2 changes: 1 addition & 1 deletion lita-onewheel-duckduckgo.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'lita-onewheel-duckduckgo'
spec.version = '0.0.1'
spec.version = '0.0.2'
spec.authors = ['Andrew Kreps']
spec.email = ['andrew.kreps@gmail.com']
spec.description = 'Lita handler for Duck Duck Go\'s answers engine.'
Expand Down
17 changes: 13 additions & 4 deletions spec/lita/handlers/onewheel_duckduckgo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@
before(:each) do
end

def mock(file)
mock_result_json = File.open("spec/fixtures/#{file}.json").read
allow(RestClient).to receive(:get).and_return( mock_result_json)
end

it { is_expected.to route_command('duck something') }

it 'does neat ducky things' do
mock_result_json = File.open('spec/fixtures/mock_result.json').read
allow(RestClient).to receive(:get).and_return(JSON.parse mock_result_json)
mock('mock_result')
send_command 'duck yo'
expect(replies.last).to include('DuckDuckGo Result: DuckDuckGo is an Internet search engine that emphasizes')
end

it 'uses the url unless the abstract exists' do
mock_result_json = File.open('spec/fixtures/mock_no_abstract.json').read
allow(RestClient).to receive(:get).and_return(JSON.parse mock_result_json)
mock('mock_no_abstract')
send_command 'duck yo'
expect(replies.last).to include('DuckDuckGo Result: https://en.wikipedia.org/wiki/Duck_(disambiguation)')
end

it 'checks for go' do
mock('mock_go')
send_command 'duck go'
expect(replies.last).to include('DuckDuckGo Result: https://en.wikipedia.org/wiki/Go')
end
end

0 comments on commit f601075

Please sign in to comment.