Skip to content

Commit e164077

Browse files
committed
✨ RSPec を qiita_trend 0.4.9 に対応させる
1 parent 91d6eee commit e164077

File tree

4 files changed

+30
-67
lines changed

4 files changed

+30
-67
lines changed

qiita_commands/command_line.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22

33
require 'optparse'
44
require 'qiita_trend'
5+
require 'highline/import'
56
require_relative './errors/invalid_option'
67

78
module QiitaCommands
89
class CLI
910
attr_accessor :options
1011

1112
def initialize
12-
@options = { target: 'daily', new: false }
13+
@options = { target: 'normal', new: false }
1314
opts = OptionParser.new
1415

15-
opts.on('-d', '--daily', 'get daily qiita trend') { @options[:target] = QiitaTrend::TrendType::DAILY }
16-
opts.on('-p', '--personal', 'get personal qiita trend') { @options[:target] = QiitaTrend::TrendType::PERSONAL }
17-
opts.on('-n', '--new', 'get qiita trend for new article') { |v| @options[:new] = v }
16+
opts.on('-n', '--normal', 'get normal qiita trend') { @options[:target] = QiitaTrend::TrendType::NORMAL }
17+
opts.on('-p', '--personal', 'get personal qiita trend') { @options[:target] = QiitaTrend::TrendType::PERSONAL }
18+
opts.on('--new', 'get qiita trend for new article') { |v| @options[:new] = v }
1819

19-
raise QiitaCommands::InvalidOption, 'Invalid option: Multiple daily and weekly and monthly cannot be specified.' unless valid_args?
20+
raise QiitaCommands::InvalidOption, 'Invalid option: Multiple normal and personal cannot be specified.' unless valid_args?
2021

2122
opts.parse!(ARGV)
2223
rescue OptionParser::InvalidOption => e
@@ -38,8 +39,8 @@ def get(name)
3839
private
3940

4041
def valid_args?
41-
# daily, personal の指定が複数あった場合は不正と判断する
42-
return false if ARGV.grep(/\A(-d|-p|--daily|--personal|)\z/).length >= 2
42+
# normal, personal の指定が複数あった場合は不正と判断する
43+
return false if ARGV.grep(/\A(-n|-p|--normal|--personal|)\z/).length >= 2
4344

4445
true
4546
end

qiita_commands/trend.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def initialize(type)
1515
end
1616

1717
def normal?
18-
type == QiitaTrend::TrendType::NOMARL
18+
type == QiitaTrend::TrendType::NORMAL
1919
end
2020

2121
def personal?

spec/command_line_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ module QiitaCommands
2222
include_examples 'system shutdown'
2323
end
2424

25-
context 'when multiple -d and -w and -m specified' do
26-
let(:argv) { %w[-w -m] }
25+
context 'when multiple -n and -p specified' do
26+
let(:argv) { %w[-n -p] }
2727

2828
include_examples 'system shutdown'
2929
end
3030

31-
context 'when multiple --daily and --weekly and --monthly specified' do
32-
let(:argv) { %w[--weekly --monthly] }
31+
context 'when multiple --normal and --personal specified' do
32+
let(:argv) { %w[--normal --personal] }
3333

3434
include_examples 'system shutdown'
3535
end
@@ -60,7 +60,7 @@ module QiitaCommands
6060
include_context 'when set command line args'
6161
let(:argv) { %w[] }
6262

63-
it { expect(cli.get(:target)).to eq('daily') }
63+
it { expect(cli.get(:target)).to eq('normal') }
6464
end
6565

6666
context 'when not exists key name' do

spec/trend_spec.rb

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module QiitaCommands
1111

1212
include_context 'when disable standard output'
1313

14-
let(:type) { QiitaTrend::TrendType::WEEKLY }
14+
let(:type) { QiitaTrend::TrendType::PERSONAL }
1515

1616
before { allow(QiitaTrend::Trend).to receive(:new).with(type).and_raise(QiitaTrend::Error::LoginFailureError) }
1717

@@ -75,81 +75,43 @@ module QiitaCommands
7575
allow(QiitaTrend::Trend).to receive(:new).with(type).and_return(qiita_trend_mock)
7676
end
7777

78-
describe '#daily?' do
78+
describe '#normal?' do
7979
let(:trend) { described_class.new(type) }
8080

81-
context 'when trend type is daily' do
82-
let(:type) { QiitaTrend::TrendType::DAILY }
81+
context 'when trend type is normal' do
82+
let(:type) { QiitaTrend::TrendType::NORMAL }
8383

84-
it { expect(trend.daily?).to eq(true) }
84+
it { expect(trend.normal?).to eq(true) }
8585
end
8686

87-
context 'when trend type is weekly' do
87+
context 'when trend type is personal' do
8888
include_context 'when mocking config.yml'
89-
let(:type) { QiitaTrend::TrendType::WEEKLY }
89+
let(:type) { QiitaTrend::TrendType::PERSONAL }
9090

91-
it { expect(trend.daily?).to eq(false) }
92-
end
93-
94-
context 'when trend type is monthly' do
95-
include_context 'when mocking config.yml'
96-
let(:type) { QiitaTrend::TrendType::MONTHLY }
97-
98-
it { expect(trend.daily?).to eq(false) }
99-
end
100-
end
101-
102-
describe '#weekly?' do
103-
let(:trend) { described_class.new(type) }
104-
105-
context 'when trend type is daily' do
106-
let(:type) { QiitaTrend::TrendType::DAILY }
107-
108-
it { expect(trend.weekly?).to eq(false) }
109-
end
110-
111-
context 'when trend type is weekly' do
112-
include_context 'when mocking config.yml'
113-
let(:type) { QiitaTrend::TrendType::WEEKLY }
114-
115-
it { expect(trend.weekly?).to eq(true) }
116-
end
117-
118-
context 'when trend type is monthly' do
119-
include_context 'when mocking config.yml'
120-
let(:type) { QiitaTrend::TrendType::MONTHLY }
121-
122-
it { expect(trend.weekly?).to eq(false) }
91+
it { expect(trend.normal?).to eq(false) }
12392
end
12493
end
12594

126-
describe '#monthly?' do
95+
describe '#personal?' do
12796
let(:trend) { described_class.new(type) }
12897

129-
context 'when trend type is daily' do
130-
let(:type) { QiitaTrend::TrendType::DAILY }
131-
132-
it { expect(trend.monthly?).to eq(false) }
133-
end
134-
135-
context 'when trend type is weekly' do
136-
include_context 'when mocking config.yml'
137-
let(:type) { QiitaTrend::TrendType::WEEKLY }
98+
context 'when trend type is normal' do
99+
let(:type) { QiitaTrend::TrendType::NORMAL }
138100

139-
it { expect(trend.monthly?).to eq(false) }
101+
it { expect(trend.personal?).to eq(false) }
140102
end
141103

142-
context 'when trend type is monthly' do
104+
context 'when trend type is personal' do
143105
include_context 'when mocking config.yml'
144-
let(:type) { QiitaTrend::TrendType::MONTHLY }
106+
let(:type) { QiitaTrend::TrendType::PERSONAL }
145107

146-
it { expect(trend.monthly?).to eq(true) }
108+
it { expect(trend.personal?).to eq(true) }
147109
end
148110
end
149111

150112
shared_examples 'contains title and laikes_count and article' do
151113
include_context 'when mocking config.yml'
152-
let(:type) { QiitaTrend::TrendType::DAILY }
114+
let(:type) { QiitaTrend::TrendType::NORMAL }
153115

154116
it 'タイトル、いいね数、ページURLが含まれていること' do
155117
items.each_with_index do |item, index|

0 commit comments

Comments
 (0)