Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
oieioi committed Apr 26, 2019
1 parent 5e63972 commit 391649a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
47 changes: 47 additions & 0 deletions spec/redash_exporter/fetcher_spec.rb
@@ -1,4 +1,51 @@
# frozen_string_literal: true

RSpec.describe RedashExporter::Fetcher do
describe "#initialize" do
subject { RedashExporter::Fetcher.new('http://example.org', 'api_key', page: 1, page_size: 2) }
it { is_expected.to be_a RedashExporter::Fetcher }
end

describe '#fetch' do
let(:target) { RedashExporter::Fetcher.new('http://example.com', 'api_key', query) }
let(:query) { { page: 1, page_size: 3 } }

subject { target.fetch }

before do
allow(target).to receive(:request).and_return(res)
end

context 'Old Redash API' do
let(:query) { {} }
let(:res) do
[
JSON.parse(query_json),
JSON.parse(query_json)
]
end

it 'calls one request' do
expect(target).to receive(:request).once
expect(subject).to eq res
end
end

context 'Latest Redash API' do
let(:query) { { page: 1, page_size: 1 } }
let(:res) do
{
count: 10,
page: 1,
page_size: 1,
results: [JSON.parse(query_json)]
}
end

it 'calls request "count" times' do
expect(target).to receive(:request).exactly(10).times
expect(subject.size).to eq 10
end
end
end
end
14 changes: 14 additions & 0 deletions spec/redash_exporter/queries_spec.rb
@@ -1,4 +1,18 @@
# frozen_string_literal: true

RSpec.describe RedashExporter::Queries do
describe '#initialize' do
subject { RedashExporter::Queries.new('http://example.com', 'api_key', 'destination') }
it { is_expected.to be_a RedashExporter::Queries }
end

describe '#fetch' do
let(:target) { RedashExporter::Queries.new('http://example.com', 'api_key', 'destination') }
subject { target.fetch }
before do
mock = double('Fetcher mock', fetch: [])
allow(RedashExporter::Fetcher).to receive(:new).and_return(mock)
end
it { is_expected.to eq [] }
end
end

0 comments on commit 391649a

Please sign in to comment.