Skip to content

Commit ad3a798

Browse files
committed
style: align the spec style
update rubocop-config-crystal add rubocop-rspec fix README.md
1 parent 30522ff commit ad3a798

File tree

7 files changed

+78
-61
lines changed

7 files changed

+78
-61
lines changed

.rubocop.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
inherit_gem:
22
rubocop-config-crystal: .rubocop.yml
33

4+
plugins:
5+
- rubocop-rspec
6+
47
Metrics/BlockLength:
58
Enabled: false
69

7-
Style/MethodCallWithArgsParentheses:
8-
Enabled: true
10+
RSpec/MultipleExpectations:
11+
Enabled: false
12+
13+
RSpec/ExampleLength:
14+
Enabled: false
15+
16+
RSpec/MissingExpectationTargetMethod:
17+
Enabled: false
18+

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ gem "rspec", "~> 3.0"
1313

1414
gem "rubocop", "~> 1.21"
1515

16-
gem "rubocop-config-crystal"
16+
gem "rubocop-config-crystal", "~> 0.0.2"
17+
18+
gem "rubocop-rspec", require: false

Gemfile.lock

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ GEM
4747
rubocop-ast (1.47.1)
4848
parser (>= 3.3.7.2)
4949
prism (~> 1.4)
50-
rubocop-config-crystal (0.0.1)
50+
rubocop-config-crystal (0.0.2)
51+
rubocop-rspec (3.7.0)
52+
lint_roller (~> 1.1)
53+
rubocop (~> 1.72, >= 1.72.1)
5154
ruby-progressbar (1.13.0)
5255
unicode-display_width (3.2.0)
5356
unicode-emoji (~> 4.1)
@@ -62,7 +65,8 @@ DEPENDENCIES
6265
rs-result!
6366
rspec (~> 3.0)
6467
rubocop (~> 1.21)
65-
rubocop-config-crystal
68+
rubocop-config-crystal (~> 0.0.2)
69+
rubocop-rspec
6670

6771
BUNDLED WITH
6872
2.4.22

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
3131

3232
## Contributing
3333

34-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rs-result.
34+
Bug reports and pull requests are welcome on GitHub at https://github.com/initdc/rs-result.

Rakefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ require "bundler/gem_tasks"
44
require "rspec/core/rake_task"
55

66
RSpec::Core::RakeTask.new(:spec)
7-
87
require "rubocop/rake_task"
98

10-
RuboCop::RakeTask.new
9+
RuboCop::RakeTask.new do |task|
10+
task.plugins << "rubocop-rspec"
11+
end
1112

1213
task default: [:spec, :rubocop]

spec/rs/option_spec.rb

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe(Rs::Option) do
3+
RSpec.describe Rs::Option do
44
# https://doc.rust-lang.org/std/option/enum.Option.html
55

66
it "new" do
7-
expect { Some.new(nil) }.to(raise_error(Rs::Option::ArgumentError, "Some value cannot be nil"))
7+
expect { Some.new(nil) }.to raise_error Rs::Option::ArgumentError, "Some value cannot be nil"
88
end
99

1010
it "some?" do
1111
x = Some.new(2)
12-
expect(x.some?).to(be(true))
12+
expect(x.some?).to be true
1313

1414
x = None.new
15-
expect(x.some?).to(be(false))
15+
expect(x.some?).to be false
1616
end
1717

1818
it "some_and proc" do
1919
x = Some.new(2)
20-
expect(x.some_and).to(be(true))
21-
expect(x.some_and { |x| x > 1 }).to(be(true))
20+
expect(x.some_and).to be true
21+
expect(x.some_and { |x| x > 1 }).to be true
2222

2323
x = Some.new(0)
24-
expect(x.some_and { |x| x > 1 }).to(be(false))
24+
expect(x.some_and { |x| x > 1 }).to be false
2525

2626
x = None.new
27-
expect(x.some_and { |x| x.to_i > 1 }).to(be(false))
27+
expect(x.some_and { |x| x.to_i > 1 }).to be false
2828

2929
x = Some.new("str")
30-
expect(x.some_and { |x| x.size > 1 }).to(be(true))
30+
expect(x.some_and { |x| x.size > 1 }).to be true
3131
end
3232

3333
it "none?" do
3434
x = Some.new(2)
35-
expect(x.none?).to(be(false))
35+
expect(x.none?).to be false
3636

3737
x = None.new
38-
expect(x.none?).to(be(true))
38+
expect(x.none?).to be true
3939
end
4040

4141
it "none_or proc" do
4242
x = Some.new(2)
43-
expect(x.none_or).to(be(false))
44-
expect(x.none_or { |x| x > 1 }).to(be(true))
43+
expect(x.none_or).to be false
44+
expect(x.none_or { |x| x > 1 }).to be true
4545

4646
x = Some.new(0)
47-
expect(x.none_or { |x| x > 1 }).to(be(false))
47+
expect(x.none_or { |x| x > 1 }).to be false
4848

4949
x = None.new
50-
expect(x.none_or { |x| x.to_i > 1 }).to(be(true))
50+
expect(x.none_or { |x| x.to_i > 1 }).to be true
5151

5252
x = Some.new("str")
53-
expect(x.none_or { |x| x.size > 1 }).to(be(true))
53+
expect(x.none_or { |x| x.size > 1 }).to be true
5454
end
5555

5656
it "unwrap" do
5757
x = Some.new("air")
58-
expect(x.unwrap).to(eq("air"))
58+
expect(x.unwrap).to eq "air"
5959

6060
x = None.new
61-
expect { x.unwrap }.to(raise_error(Rs::Option::UnwrapNone))
61+
expect { x.unwrap }.to raise_error Rs::Option::UnwrapNone
6262
end
6363

6464
it "unwrap_or" do
65-
expect(Some.new("car").unwrap_or("bike")).to(eq("car"))
66-
expect(None.new.unwrap_or("bike")).to(eq("bike"))
65+
expect(Some.new("car").unwrap_or("bike")).to eq "car"
66+
expect(None.new.unwrap_or("bike")).to eq "bike"
6767
end
6868

6969
it "unwrap_or proc" do
7070
k = 10
71-
expect(Some.new(4).unwrap_or { 2 * k }).to(eq(4))
72-
expect(None.new.unwrap_or { 2 * k }).to(eq(20))
71+
expect(Some.new(4).unwrap_or { 2 * k }).to eq 4
72+
expect(None.new.unwrap_or { 2 * k }).to eq 20
7373
end
7474

7575
it "unwrap_or_else proc" do
7676
k = 10
77-
expect(Some.new(4).unwrap_or_else { 2 * k }).to(eq(4))
78-
expect(None.new.unwrap_or_else { 2 * k }).to(eq(20))
77+
expect(Some.new(4).unwrap_or_else { 2 * k }).to eq 4
78+
expect(None.new.unwrap_or_else { 2 * k }).to eq 20
7979
end
8080

8181
it "unwrap_or default" do
8282
x = None.new
8383
y = Some.new(12)
8484

85-
expect(x.unwrap_or).to(eq(nil))
86-
expect(y.unwrap_or).to(eq(12))
85+
expect(x.unwrap_or).to be_nil
86+
expect(y.unwrap_or).to eq 12
8787
end
8888
end

spec/rs/result_spec.rb

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,57 @@
44
# https://doc.rust-lang.org/std/result/enum.Result.html
55

66
it "has a version number" do
7-
expect(Rs::Result::VERSION).not_to(be(nil))
7+
expect(Rs::Result::VERSION).not_to be_nil
88
end
99

1010
it "ok?" do
1111
x = Ok.new(-3)
12-
expect(x.ok?).to(be(true))
12+
expect(x.ok?).to be true
1313

1414
x = Err.new("Some error message")
15-
expect(x.ok?).to(be(false))
15+
expect(x.ok?).to be false
1616
end
1717

1818
it "ok_and" do
1919
x = Ok.new(2)
20-
expect(x.ok_and { |x| x > 1 }).to(be(true))
20+
expect(x.ok_and { |x| x > 1 }).to be true
2121

2222
x = Ok.new(0)
23-
expect(x.ok_and { |x| x > 1 }).to(be(false))
23+
expect(x.ok_and { |x| x > 1 }).to be false
2424

2525
x = Err.new("hey")
26-
expect(x.ok_and { |x| x > 1 }).to(be(false))
26+
expect(x.ok_and { |x| x > 1 }).to be false
2727

2828
x = Ok.new("str")
29-
expect(x.ok_and { |x| x.size > 1 }).to(be(true))
29+
expect(x.ok_and { |x| x.size > 1 }).to be true
3030
end
3131

3232
it "err?" do
3333
x = Ok.new(-3)
34-
expect(x.err?).to(be(false))
34+
expect(x.err?).to be false
3535

3636
x = Err.new("Some error message")
37-
expect(x.err?).to(be(true))
37+
expect(x.err?).to be true
3838
end
3939

4040
it "err_and" do
4141
x = Err.new(Errno::ENOENT)
42-
expect(x.err_and { |x| x == Errno::ENOENT }).to(be(true))
42+
expect(x.err_and { |x| x == Errno::ENOENT }).to be true
4343

4444
x = Err.new(Errno::EACCES)
45-
expect(x.err_and { |x| x == Errno::ENOENT }).to(be(false))
45+
expect(x.err_and { |x| x == Errno::ENOENT }).to be false
4646

4747
x = Ok.new(123)
48-
expect(x.err_and { |x| x == Errno::ENOENT }).to(be(false))
48+
expect(x.err_and { |x| x == Errno::ENOENT }).to be false
4949

5050
x = Err.new("str")
51-
expect(x.err_and { |x| x.size > 1 }).to(be(true))
51+
expect(x.err_and { |x| x.size > 1 }).to be true
5252
end
5353

5454
it "ok" do
5555
x = Ok.new(2)
5656
expect(x.ok).is_a?(Some)
57-
expect(x.unwrap).to(eq(2))
57+
expect(x.unwrap).to eq 2
5858

5959
x = Err.new("Nothing here")
6060
expect(x.ok).is_a?(None)
@@ -66,22 +66,22 @@
6666

6767
x = Err.new("Nothing here")
6868
expect(x.err).is_a?(Some)
69-
expect(x.unwrap_err).to(eq("Nothing here"))
69+
expect(x.unwrap_err).to eq "Nothing here"
7070
end
7171

7272
it "expect" do
7373
x = Err.new("emergency failure")
74-
expect { x.expect("Testing expect") }.to(raise_error(Rs::Result::UnwrapOnErr, "Testing expect: emergency failure"))
74+
expect { x.expect("Testing expect") }.to raise_error Rs::Result::UnwrapOnErr, "Testing expect: emergency failure"
7575
end
7676

7777
it "unwrap" do
7878
x = Ok.new(2)
79-
expect(x.unwrap).to(eq(2))
79+
expect(x.unwrap).to eq 2
8080

8181
x = Err.new("emergency failure")
8282
expect {
8383
x.unwrap
84-
}.to(raise_error(Rs::Result::UnwrapOnErr, "called `Result::unwrap()` on an `Err` value: emergency failure"))
84+
}.to raise_error Rs::Result::UnwrapOnErr, "called `Result::unwrap()` on an `Err` value: emergency failure"
8585
end
8686

8787
it "unwrap_or default" do
@@ -101,36 +101,36 @@ def parse_year(str)
101101
good_year = parse_year(good_year_from_input).unwrap_or(0)
102102
bad_year = parse_year(bad_year_from_input).unwrap_or(0)
103103

104-
expect(good_year).to(eq(1909))
105-
expect(bad_year).to(eq(0))
104+
expect(good_year).to eq 1909
105+
expect(bad_year).to eq 0
106106
end
107107

108108
it "expect_err" do
109109
x = Ok.new(10)
110-
expect { x.expect_err("Testing expect_err") }.to(raise_error(Rs::Result::UnwrapErrOnOk, "Testing expect_err: 10"))
110+
expect { x.expect_err("Testing expect_err") }.to raise_error Rs::Result::UnwrapErrOnOk, "Testing expect_err: 10"
111111
end
112112

113113
it "unwrap_err" do
114114
x = Ok.new(2)
115115
expect {
116116
x.unwrap_err
117-
}.to(raise_error(Rs::Result::UnwrapErrOnOk, "called `Result::unwrap_err()` on an `Ok` value: 2"))
117+
}.to raise_error Rs::Result::UnwrapErrOnOk, "called `Result::unwrap_err()` on an `Ok` value: 2"
118118

119119
x = Err.new("emergency failure")
120-
expect(x.unwrap_err).to(eq("emergency failure"))
120+
expect(x.unwrap_err).to eq "emergency failure"
121121
end
122122

123123
it "unwrap_or" do
124124
default = 2
125125
x = Ok.new(9)
126-
expect(x.unwrap_or(default)).to(eq(9))
126+
expect(x.unwrap_or(default)).to eq 9
127127

128128
x = Err.new("error")
129-
expect(x.unwrap_or(default)).to(eq(default))
129+
expect(x.unwrap_or(default)).to eq default
130130
end
131131

132132
it "unwrap_or_else" do
133-
expect(Ok.new(2).unwrap_or_else { |x| x.size }).to(eq(2))
134-
expect(Err.new("foo").unwrap_or_else { |x| x.size }).to(eq(3))
133+
expect(Ok.new(2).unwrap_or_else { |x| x.size }).to eq 2
134+
expect(Err.new("foo").unwrap_or_else { |x| x.size }).to eq 3
135135
end
136136
end

0 commit comments

Comments
 (0)