Skip to content

Commit 10a116c

Browse files
author
Konstantin Gredeskoul
committed
Fixing CI and tests
1 parent 4099472 commit 10a116c

File tree

13 files changed

+216
-59
lines changed

13 files changed

+216
-59
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ AllCops:
66
- "**/rubocop"
77
- "examples/**/*"
88
- "bazel-*/**/*"
9-
- "**/external/**/*"
9+
- "external/**/*"
1010
- "**/vendor/bundle/**/*"
1111

1212

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1-
inherit_from: .relaxed-rubocop-2.4.yml
1+
inherit_from: ~/.relaxed-rubocop-2.4.yml
22

33
AllCops:
4-
TargetRubyVersion: 2.6.5
4+
TargetRubyVersion: 2.6
5+
UseCache: true
6+
DefaultFormatter: progress
7+
DisplayStyleGuide: true
8+
DisplayCopNames: true
59
Exclude:
6-
- rubocop
7-
- bazel-*/**/*
8-
- external/**/*
10+
- "external*/**/*"
11+
- "bazel-*/**/*"
12+
- "**/examples/**/*"
13+
- "**/BUILD"
14+
- "**/*.bazel"
15+
- "**/*.bzl"
16+
- "**/rubocop"
917
- "**/vendor/bundle/**/*"
18+
Include:
19+
- '**/*.rb'
20+
- '**/*.gemfile'
21+
- '**/*.gemspec'
22+
- '**/*.rake'
23+
- '**/*.ru'
24+
- '**/Gemfile'
25+
- '**/Rakefile'
1026

27+
Layout/HashAlignment:
28+
Enabled: true
29+
EnforcedColonStyle: table
30+
31+
Style/Dir:
32+
Enabled: false
1133

34+
# In Bazel we want to use __FILE__ because __dir__points to the actual sources
35+
Style/ExpandPathArguments:
36+
Enabled: false

examples/simple_script/BUILD

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,59 @@ package(default_visibility = ["//:__subpackages__"])
33
load(
44
"@bazelruby_ruby_rules//ruby:defs.bzl",
55
"ruby_binary",
6+
"ruby_library",
67
"ruby_test",
78
)
89

10+
ruby_library(
11+
name = "script.lib",
12+
srcs = [
13+
"script.rb",
14+
"//lib:foo",
15+
],
16+
deps = [
17+
"@bundle//:awesome_print",
18+
"@bundle//:colored2",
19+
],
20+
)
21+
922
ruby_binary(
10-
name = "default_bin",
23+
name = "bin",
1124
srcs = ["script.rb"],
1225
main = "script.rb",
1326
deps = [
27+
":script.lib",
1428
"//lib:foo",
1529
"@bundle//:awesome_print",
30+
"@bundle//:colored2",
1631
],
1732
)
1833

1934
ruby_test(
20-
name = "script_spec",
35+
name = "rspec",
2136
timeout = "short",
2237
srcs = [
2338
"script.rb",
39+
"spec/lib/foo_spec.rb",
2440
"spec/script_spec.rb",
41+
"spec/spec_helper.rb",
42+
"@bundle//:bin/rspec",
43+
],
44+
args = [
45+
"spec",
46+
],
47+
includes = [
48+
".",
49+
"lib",
50+
"spec",
2551
],
26-
main = "spec/script_spec.rb",
27-
rubyopt = ["-rrspec/autorun"], # require autorun because it is needed
52+
main = "spec/spec_helper.rb",
2853
deps = [
2954
"//lib:foo",
3055
"@bundle//:awesome_print",
56+
"@bundle//:colored2",
3157
"@bundle//:rspec",
58+
"@bundle//:rspec-its",
3259
],
3360
)
3461

@@ -39,7 +66,9 @@ ruby_binary(
3966
".relaxed-rubocop-2.4.yml",
4067
".rubocop.yml",
4168
"script.rb",
69+
"spec/lib/foo_spec.rb",
4270
"spec/script_spec.rb",
71+
"spec/spec_helper.rb",
4372
"@bundle//:bin/rubocop",
4473
],
4574
args = [
@@ -50,6 +79,7 @@ ruby_binary(
5079
],
5180
main = "@bundle//:bin/rubocop",
5281
deps = [
82+
"//lib:foo",
5383
"@bundle//:rubocop",
5484
],
5585
)

examples/simple_script/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ source 'https://rubygems.org'
55
gem 'awesome_print'
66
gem 'colored2'
77
gem 'rspec', '~> 3.7.0'
8+
gem 'rspec-its'
89
gem 'rubocop', '~> 0.78.0'

examples/simple_script/Gemfile.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ GEM
1919
rspec-expectations (3.7.0)
2020
diff-lcs (>= 1.2.0, < 2.0)
2121
rspec-support (~> 3.7.0)
22+
rspec-its (1.3.0)
23+
rspec-core (>= 3.0.0)
24+
rspec-expectations (>= 3.0.0)
2225
rspec-mocks (3.7.0)
2326
diff-lcs (>= 1.2.0, < 2.0)
2427
rspec-support (~> 3.7.0)
@@ -40,7 +43,8 @@ DEPENDENCIES
4043
awesome_print
4144
colored2
4245
rspec (~> 3.7.0)
46+
rspec-its
4347
rubocop (~> 0.78.0)
4448

4549
BUNDLED WITH
46-
2.1.0
50+
2.1.2

examples/simple_script/lib/foo.rb

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

3-
module Foo
4-
def self.aha
5-
"aha"
3+
class Foo
4+
class << self
5+
def yell_aha
6+
puts aha
7+
end
8+
9+
def aha
10+
'You said, aha?'
11+
end
12+
13+
def rot13(value)
14+
return nil unless value.is_a?(String)
15+
16+
value.tr('abcdefghijklmnopqrstuvwxyz', 'nopqrstuvwxyzabcdefghijklm')
17+
end
18+
end
19+
20+
attr_reader :goo, :foo
21+
22+
def initialize(goo)
23+
@goo = goo
24+
@foo = transform(goo)
25+
end
26+
27+
def transform(incoming = goo)
28+
Foo.rot13(incoming)
629
end
730
end

examples/simple_script/script.rb

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

3+
require 'colored2'
34
require 'openssl'
4-
require 'lib/foo'
55
require 'awesome_print'
66

7+
require_relative 'lib/foo'
8+
79
def oss_rand
810
OpenSSL::BN.rand(512).to_s
911
end
1012

1113
puts Foo.aha + ' ' + oss_rand
1214

13-
puts $LOAD_PATH
14-
15-
ap Class
15+
ap Class.to_s
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../spec_helper'
4+
require_relative '../../lib/foo'
5+
6+
RSpec.describe Foo do
7+
let(:goo) { 'Green slime was dripping down his throat into his lapdomen...' }
8+
subject(:foo) { Foo.new(goo) }
9+
10+
context 'without the aha' do
11+
before { allow(Foo).to receive(:yell_aha).and_return('tiny dongle') }
12+
13+
its(:goo) { should eq goo }
14+
its(:transform) { should_not eq goo }
15+
16+
# Some rot13 old school encryption :)
17+
its(:transform) { should eq 'Gerra fyvzr jnf qevccvat qbja uvf guebng vagb uvf yncqbzra...' }
18+
end
19+
20+
context 'aha' do
21+
it 'should print aha' do
22+
expect(Foo).to receive(:puts).with('You said, aha?').and_return(nil)
23+
Foo.yell_aha
24+
end
25+
end
26+
end

examples/simple_script/spec/script_spec.rb

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
# frozen_string_literal: true
22

3-
RSpec.configure do |config|
4-
config.expect_with :rspec do |expectations|
5-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6-
end
7-
8-
config.mock_with :rspec do |mocks|
9-
mocks.verify_partial_doubles = true
10-
end
11-
12-
config.shared_context_metadata_behavior = :apply_to_host_groups
13-
14-
config.warnings = true
15-
config.filter_run_when_matching :focus
16-
# config.disable_monkey_patching!
17-
config.order = :random
18-
Kernel.srand config.seed
19-
end
20-
21-
# Sets HOME here because:
22-
# If otherwise, it causes a runtime failure with the following steps.
23-
# 1. RSpec::Core::ConfigurationOptions.global_options_file raises an exception
24-
# because $HOME is not set in the sandbox environment of Bazel
25-
# 2. the rescue clause calls RSpec::Support.#warning
26-
# 3. #warning calls #warn_with
27-
# 4. #warn_with tries to lookup the first caller which is not a part of RSpec.
28-
# But all the call stack entires are about RSpec at this time because
29-
# it is invoked by rpsec/autorun. So #warn_with raises an exception
30-
# 5. The process fails with an unhandled exception.
31-
ENV['HOME'] ||= '/'
32-
3+
require 'spec_helper'
334
require_relative '../script'
345

356
describe 'oss_rand' do
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
require 'rspec'
4+
require 'rspec/its'
5+
require 'awesome_print'
6+
require 'colored2'
7+
8+
# frozen_string_literal: true
9+
RSpec.configure do |config|
10+
config.expect_with :rspec do |expectations|
11+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
12+
end
13+
14+
config.mock_with :rspec do |mocks|
15+
mocks.verify_partial_doubles = true
16+
end
17+
18+
config.shared_context_metadata_behavior = :apply_to_host_groups
19+
20+
config.warnings = true
21+
config.filter_run_when_matching :focus
22+
# config.disable_monkey_patching!
23+
config.order = :random
24+
Kernel.srand config.seed
25+
end
26+
27+
if $0 == 'rspec'
28+
require_relative '../script'
29+
require_relative '../lib/foo'
30+
require_relative './script_spec'
31+
require_relative './lib/foo_spec'
32+
end
33+
34+
# Sets HOME here because:
35+
# If otherwise, it causes a runtime failure with the following steps.
36+
# 1. RSpec::Core::ConfigurationOptions.global_options_file raises an exception
37+
# because $HOME is not set in the sandbox environment of Bazel
38+
# 2. the rescue clause calls RSpec::Support.#warning
39+
# 3. #warning calls #warn_with
40+
# 4. #warn_with tries to lookup the first caller which is not a part of RSpec.
41+
# But all the call stack entires are about RSpec at this time because
42+
# it is invoked by rpsec/autorun. So #warn_with raises an exception
43+
# 5. The process fails with an unhandled exception.
44+
# ENV['HOME'] ||= '/'

0 commit comments

Comments
 (0)