qiita_scouter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,188 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'qiita_scouter_calculator'
4
+ require 'models/user'
5
+ require 'models/article'
6
+ require 'models/articles'
7
+
8
+ # rubocop:disable LineLength, UnusedMethodArgument
9
+ describe QiitaScouter::Calculator do
10
+ user = QiitaScouter::User.new(
11
+ 'url_name' => 'tbpgr',
12
+ 'followers' => 10,
13
+ 'items' => 20
14
+ )
15
+ articles = QiitaScouter::Articles.new([
16
+ QiitaScouter::Article.new(
17
+ 'tags' => [
18
+ { 'name' => 'Ruby' },
19
+ { 'name' => 'Graphviz' }
20
+ ],
21
+ 'stock_count' => 25
22
+ ),
23
+ QiitaScouter::Article.new(
24
+ 'tags' => [
25
+ { 'name' => 'PHP' },
26
+ { 'name' => 'Graphviz' }
27
+ ],
28
+ 'stock_count' => 32
29
+ )
30
+ ])
31
+
32
+ context :calc_strength do
33
+ cases = [
34
+ {
35
+ case_no: 1,
36
+ case_title: 'valid case',
37
+ user: user,
38
+ articles: articles,
39
+ expected: 10 * 10 * (50 / 10)
40
+ }
41
+ ]
42
+
43
+ cases.each do |c|
44
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
45
+ begin
46
+ case_before c
47
+
48
+ # -- given --
49
+ qiita_scouter_calculator = QiitaScouter::Calculator.new(c[:user], c[:articles])
50
+
51
+ # -- when --
52
+ actual = qiita_scouter_calculator.calc_strength
53
+
54
+ # -- then --
55
+ expect(actual).to eq(c[:expected])
56
+ ensure
57
+ case_after c
58
+ end
59
+ end
60
+
61
+ def case_before(_c)
62
+ # implement each case before
63
+ end
64
+
65
+ def case_after(_c)
66
+ # implement each case after
67
+ end
68
+ end
69
+ end
70
+
71
+ context :calc_intelligence do
72
+ cases = [
73
+ {
74
+ case_no: 1,
75
+ case_title: 'valid case',
76
+ user: user,
77
+ articles: articles,
78
+ expected: 20 * 5 * (50 / 10)
79
+ }
80
+ ]
81
+
82
+ cases.each do |c|
83
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
84
+ begin
85
+ case_before c
86
+
87
+ # -- given --
88
+ qiita_scouter_calculator = QiitaScouter::Calculator.new(c[:user], c[:articles])
89
+
90
+ # -- when --
91
+ actual = qiita_scouter_calculator.calc_intelligence
92
+
93
+ # -- then --
94
+ expect(actual).to eq(c[:expected])
95
+ ensure
96
+ case_after c
97
+ end
98
+ end
99
+
100
+ def case_before(_c)
101
+ # implement each case before
102
+ end
103
+
104
+ def case_after(_c)
105
+ # implement each case after
106
+ end
107
+ end
108
+ end
109
+
110
+ context :calc_quickness do
111
+ cases = [
112
+ {
113
+ case_no: 1,
114
+ case_title: 'valid case',
115
+ user: user,
116
+ articles: articles,
117
+ expected: 3 * (50 / 10)
118
+ }
119
+ ]
120
+
121
+ cases.each do |c|
122
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
123
+ begin
124
+ case_before c
125
+
126
+ # -- given --
127
+ qiita_scouter_calculator = QiitaScouter::Calculator.new(c[:user], c[:articles])
128
+
129
+ # -- when --
130
+ actual = qiita_scouter_calculator.calc_quickness
131
+
132
+ # -- then --
133
+ expect(actual).to eq(c[:expected])
134
+ ensure
135
+ case_after c
136
+ end
137
+ end
138
+
139
+ def case_before(_c)
140
+ # implement each case before
141
+ end
142
+
143
+ def case_after(_c)
144
+ # implement each case after
145
+ end
146
+ end
147
+ end
148
+
149
+ context :calc_power_level do
150
+ cases = [
151
+ {
152
+ case_no: 1,
153
+ case_title: 'valid case',
154
+ user: user,
155
+ articles: articles,
156
+ expected: (10 * 10 * (50 / 10)) + (20 * 5 * (50 / 10)) + (3 * (50 / 10))
157
+ }
158
+ ]
159
+
160
+ cases.each do |c|
161
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
162
+ begin
163
+ case_before c
164
+
165
+ # -- given --
166
+ qiita_scouter_calculator = QiitaScouter::Calculator.new(c[:user], c[:articles])
167
+
168
+ # -- when --
169
+ actual = qiita_scouter_calculator.calc_power_level
170
+
171
+ # -- then --
172
+ expect(actual).to eq(c[:expected])
173
+ ensure
174
+ case_after c
175
+ end
176
+ end
177
+
178
+ def case_before(_c)
179
+ # implement each case before
180
+ end
181
+
182
+ def case_after(_c)
183
+ # implement each case after
184
+ end
185
+ end
186
+ end
187
+ end
188
+ # rubocop:enable LineLength, UnusedMethodArgument
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'qiita_user_json_loader'
4
+ require 'json'
5
+ require 'open-uri'
6
+ require 'openssl'
7
+ require 'models/user'
8
+
9
+ describe QiitaScouter::QiitaUserJsonLoader do
10
+ context :load do
11
+ cases = [
12
+ {
13
+ case_no: 1,
14
+ case_title: 'valid case',
15
+ user: 'user',
16
+ expected_url_name: 'tbpgr',
17
+ expected_followers: 14,
18
+ expected_items: 226
19
+ }
20
+ ]
21
+
22
+ # Dummy
23
+ class Dummy
24
+ def read
25
+ <<-EOS
26
+ {"id":43480,
27
+ "url_name":"tbpgr",
28
+ "followers":14,
29
+ "items":226
30
+ }
31
+ EOS
32
+ end
33
+ end
34
+
35
+ cases.each do |c|
36
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
37
+ begin
38
+ case_before c
39
+
40
+ # -- given --
41
+ qiita_json_loader = QiitaScouter::QiitaUserJsonLoader.new
42
+ qiita_json_loader.stub(:open).and_return(Dummy.new)
43
+
44
+ # -- when --
45
+ qiita_json_loader.load(c[:user])
46
+ actual_user = qiita_json_loader.user
47
+
48
+ # -- then --
49
+ expect(actual_user.url_name).to eq(c[:expected_url_name])
50
+ expect(actual_user.followers).to eq(c[:expected_followers])
51
+ expect(actual_user.items).to eq(c[:expected_items])
52
+ ensure
53
+ case_after c
54
+ end
55
+ end
56
+
57
+ def case_before(c) # rubocop:disable UnusedMethodArgument
58
+ # implement each case before
59
+ end
60
+
61
+ def case_after(c) # rubocop:disable UnusedMethodArgument
62
+ # implement each case after
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter '/spec/'
11
+ end
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qiita_scouter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - tbpgr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.18.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.14'
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: 2.14.1
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.14'
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.14.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.8'
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 0.8.2
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '0.8'
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 0.8.2
67
+ - !ruby/object:Gem::Dependency
68
+ name: bundler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: '1.6'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: '1.6'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: Analyze your qiita power
96
+ email:
97
+ - tbpgr@tbpgr.jp
98
+ executables:
99
+ - qiita_scouter
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .coveralls.yml
104
+ - .gitignore
105
+ - .rspec
106
+ - .rubocop.yml
107
+ - .travis.yml
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/qiita_scouter
113
+ - lib/models/article.rb
114
+ - lib/models/articles.rb
115
+ - lib/models/user.rb
116
+ - lib/qiita_items_json_loader.rb
117
+ - lib/qiita_scouter/version.rb
118
+ - lib/qiita_scouter_calculator.rb
119
+ - lib/qiita_scouter_core.rb
120
+ - lib/qiita_user_json_loader.rb
121
+ - qiita_scouter.gemspec
122
+ - spec/models/article_spec.rb
123
+ - spec/models/articles_spec.rb
124
+ - spec/models/user_spec.rb
125
+ - spec/qiita_items_json_loader_spec.rb
126
+ - spec/qiita_scouter_calculator_spec.rb
127
+ - spec/qiita_user_json_loader_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: https://github.com/tbpgr/qiita_scouter
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.3.0
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Analyze your qiita power
153
+ test_files:
154
+ - spec/models/article_spec.rb
155
+ - spec/models/articles_spec.rb
156
+ - spec/models/user_spec.rb
157
+ - spec/qiita_items_json_loader_spec.rb
158
+ - spec/qiita_scouter_calculator_spec.rb
159
+ - spec/qiita_user_json_loader_spec.rb
160
+ - spec/spec_helper.rb