Skip to content

Commit 89181ae

Browse files
committed
Add Rspec test
1 parent f0bed3e commit 89181ae

File tree

6 files changed

+89
-12
lines changed

6 files changed

+89
-12
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Bundler
2+
Gemfile.lock
23
/.bundle
34
/vendor/bundle
45

56
# OS Specific
67
.DS_Store
7-
Thumbs.db
8+
Thumbs.db
9+
10+
# dotenv
11+
.env

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--format progress

Gemfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
source 'https://rubygems.org'
22

3-
gem 'rake'
3+
group :development do
4+
gem 'dotenv'
5+
gem 'rspec'
6+
end

Gemfile.lock

Lines changed: 0 additions & 10 deletions
This file was deleted.

spec/alfred_qiita_spec.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
require_relative '../lib/qiita'
2+
3+
require 'dotenv'
4+
Dotenv.load!
5+
6+
describe Qiita::API do
7+
describe "Qiita::API#setup called" do
8+
before do
9+
# Stub
10+
Qiita::API.should_receive(:auth).and_return({"url_name"=>"o_ame", "token"=>"836b54f92f3445c89352916d4c0c8bdd"})
11+
12+
@response = Qiita::API.auth name: ENV['NAME'], password: ENV['PASS']
13+
end
14+
15+
it 'Response should be Hash' do
16+
@response.class.should eq Hash
17+
end
18+
19+
it 'Response has url_name and token keys' do
20+
@response.should have_key('url_name')
21+
@response.should have_key('token')
22+
end
23+
end
24+
25+
describe "Qiita::API#search called" do
26+
before do
27+
@response = Qiita::API.search('rspec')
28+
end
29+
30+
it 'Response should be Hash' do
31+
@response.class.should eq Array
32+
end
33+
34+
describe 'First item of array' do
35+
let(:item) { @response.first }
36+
37+
it 'Response has necessary keys' do
38+
item.keys.should include('id', 'url', 'title', 'stock_count', 'comment_count', 'created_at')
39+
end
40+
end
41+
end
42+
43+
describe "Qiita::API#search called with stocks" do
44+
before do
45+
config = Qiita::Config.new
46+
@response = Qiita::API.search('rspec', token: config.token, stocked: 1)
47+
end
48+
49+
it 'Response should be Hash' do
50+
@response.class.should eq Array
51+
end
52+
53+
describe 'First item of array' do
54+
let(:item) { @response.first }
55+
56+
it 'Response has necessary keys' do
57+
item.keys.should include('id', 'url', 'title', 'stock_count', 'comment_count', 'created_at')
58+
end
59+
end
60+
end
61+
end

spec/spec_helper.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file was generated by the `rspec --init` command. Conventionally, all
2+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3+
# Require this file using `require "spec_helper"` to ensure that it is only
4+
# loaded once.
5+
#
6+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7+
RSpec.configure do |config|
8+
config.treat_symbols_as_metadata_keys_with_true_values = true
9+
config.run_all_when_everything_filtered = true
10+
config.filter_run :focus
11+
12+
# Run specs in random order to surface order dependencies. If you find an
13+
# order dependency and want to debug it, you can fix the order by providing
14+
# the seed, which is printed after each run.
15+
# --seed 1234
16+
config.order = 'random'
17+
end

0 commit comments

Comments
 (0)