sinclair 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +5 -3
- data/.rubocop.yml +20 -4
- data/Dockerfile +8 -4
- data/README.md +1 -1
- data/config/yardstick.yml +10 -35
- data/lib/sinclair.rb +87 -18
- data/lib/sinclair/config.rb +3 -0
- data/lib/sinclair/config/methods_builder.rb +15 -1
- data/lib/sinclair/config_builder.rb +1 -0
- data/lib/sinclair/config_class.rb +1 -0
- data/lib/sinclair/config_factory.rb +15 -0
- data/lib/sinclair/configurable.rb +1 -0
- data/lib/sinclair/matchers.rb +20 -6
- data/lib/sinclair/matchers/add_class_method.rb +56 -0
- data/lib/sinclair/matchers/add_class_method_to.rb +98 -0
- data/lib/sinclair/matchers/add_instance_method.rb +85 -0
- data/lib/sinclair/matchers/add_instance_method_to.rb +119 -0
- data/lib/sinclair/matchers/add_method.rb +11 -73
- data/lib/sinclair/matchers/add_method_to.rb +13 -111
- data/lib/sinclair/method_definition.rb +18 -58
- data/lib/sinclair/method_definition/block_definition.rb +37 -6
- data/lib/sinclair/method_definition/class_block_definition.rb +22 -0
- data/lib/sinclair/method_definition/class_method_definition.rb +50 -0
- data/lib/sinclair/method_definition/class_string_definition.rb +24 -0
- data/lib/sinclair/method_definition/instance_block_definition.rb +22 -0
- data/lib/sinclair/method_definition/instance_method_definition.rb +48 -0
- data/lib/sinclair/method_definition/instance_string_definition.rb +24 -0
- data/lib/sinclair/method_definition/string_definition.rb +39 -5
- data/lib/sinclair/method_definitions.rb +28 -0
- data/lib/sinclair/options_parser.rb +5 -0
- data/lib/sinclair/version.rb +1 -1
- data/sinclair.gemspec +16 -10
- data/spec/integration/yard/sinclair/matchers/add_class_method_spec.rb +23 -0
- data/spec/integration/yard/sinclair/matchers/add_class_method_to_spec.rb +19 -0
- data/spec/integration/yard/sinclair/matchers/{add_method_spec.rb → add_instance_method_spec.rb} +3 -3
- data/spec/integration/yard/sinclair/matchers/{add_method_to_spec.rb → add_instance_method_to_spec.rb} +1 -1
- data/spec/integration/yard/sinclair/method_definition/class_block_definition_spec.rb +34 -0
- data/spec/integration/yard/sinclair/method_definition/class_method_definition_spec.rb +28 -0
- data/spec/integration/yard/sinclair/method_definition/class_string_definition_spec.rb +23 -0
- data/spec/integration/yard/sinclair/method_definition/{block_definition_spec.rb → instance_block_definition_spec.rb} +2 -2
- data/spec/integration/yard/sinclair/method_definition/instance_method_definition_spec.rb +35 -0
- data/spec/integration/yard/sinclair/method_definition/{string_definition_spec.rb → instance_string_definition_spec.rb} +1 -1
- data/spec/integration/yard/sinclair_spec.rb +32 -5
- data/spec/lib/sinclair/matchers/add_class_method_spec.rb +36 -0
- data/spec/lib/sinclair/matchers/add_class_method_to_spec.rb +77 -0
- data/spec/lib/sinclair/matchers/{add_method_spec.rb → add_instance_method_spec.rb} +11 -4
- data/spec/lib/sinclair/matchers/{add_method_to_spec.rb → add_instance_method_to_spec.rb} +2 -2
- data/spec/lib/sinclair/matchers_spec.rb +17 -2
- data/spec/lib/sinclair/method_definition/class_block_definition_spec.rb +29 -0
- data/spec/lib/sinclair/method_definition/class_string_definition_spec.rb +27 -0
- data/spec/lib/sinclair/method_definition/{block_definition_spec.rb → instance_block_definition_spec.rb} +2 -2
- data/spec/lib/sinclair/method_definition/{string_definition_spec.rb → instance_string_definition_spec.rb} +2 -2
- data/spec/lib/sinclair/method_definition_spec.rb +52 -6
- data/spec/lib/sinclair_spec.rb +83 -0
- data/spec/support/models/dummy_class_builder.rb +11 -0
- data/spec/support/shared_examples/class_method_definition.rb +96 -0
- data/spec/support/shared_examples/{method_definition.rb → instance_method_definition.rb} +0 -0
- metadata +148 -45
- data/scripts/check_readme.sh +0 -6
- data/scripts/rubycritic.sh +0 -10
- data/spec/integration/sinclair/matchers_spec.rb +0 -99
- data/spec/integration/yard/sinclair/method_definition_spec.rb +0 -56
data/scripts/check_readme.sh
DELETED
data/scripts/rubycritic.sh
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
DIFF_LIST=$(git diff --name-only $CIRCLE_SHA1 $(git merge-base $CIRCLE_SHA1 origin/master) | grep "^lib/")
|
4
|
-
|
5
|
-
if [ ! -z "$DIFF_LIST" ]; then
|
6
|
-
mkdir -p tmp/rubycritic/compare
|
7
|
-
bundle exec rubycritic --format console --branch origin/master -t 0 --maximum-decrease 1 $DIFF_LIST
|
8
|
-
else
|
9
|
-
echo "No changes detected. Skipping rubycritic..."
|
10
|
-
fi
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Sinclair::Matchers do
|
6
|
-
describe 'add_method_to' do
|
7
|
-
let(:method) { :the_method }
|
8
|
-
let(:klass) { Class.new }
|
9
|
-
let(:instance) { klass.new }
|
10
|
-
let(:expectation) do
|
11
|
-
expect { block.call }.to add_method(method).to(instance)
|
12
|
-
end
|
13
|
-
let(:block) { proc { klass.send(:define_method, method) {} } }
|
14
|
-
|
15
|
-
context 'when method is added' do
|
16
|
-
it 'returns a succes' do
|
17
|
-
expect { expectation }.not_to raise_error
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when method is not added' do
|
22
|
-
let(:block) { proc {} }
|
23
|
-
|
24
|
-
it 'raises expectation error' do
|
25
|
-
expect { expectation }.to raise_error(
|
26
|
-
RSpec::Expectations::ExpectationNotMetError,
|
27
|
-
"expected 'the_method' to be added to #{klass} but it didn't"
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when method existed before' do
|
33
|
-
before do
|
34
|
-
block.call
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'raises expectation error' do
|
38
|
-
expect { expectation }.to raise_error(
|
39
|
-
RSpec::Expectations::ExpectationNotMetError,
|
40
|
-
"expected 'the_method' to be added to #{klass} but it already existed"
|
41
|
-
)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'when negating' do
|
46
|
-
let(:expectation) do
|
47
|
-
expect { block.call }.not_to add_method(method).to(instance)
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when method is not added' do
|
51
|
-
let(:block) { proc {} }
|
52
|
-
|
53
|
-
it 'returns a succes' do
|
54
|
-
expect { expectation }.not_to raise_error
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'when method is added' do
|
59
|
-
it 'raises expectation error' do
|
60
|
-
expect { expectation }.to raise_error(
|
61
|
-
RSpec::Expectations::ExpectationNotMetError,
|
62
|
-
"expected 'the_method' not to be added to #{klass} but it was"
|
63
|
-
)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'when method existed before' do
|
68
|
-
before do
|
69
|
-
block.call
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'returns a succes' do
|
73
|
-
expect { expectation }.not_to raise_error
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe 'add method' do
|
80
|
-
let(:method) { :the_method }
|
81
|
-
let(:klass) { Class.new }
|
82
|
-
let(:expectation) do
|
83
|
-
expect { block.call }.to add_method(method)
|
84
|
-
end
|
85
|
-
let(:block) { proc { klass.send(:define_method, method) {} } }
|
86
|
-
let(:expected_error) do
|
87
|
-
'You should specify which instance the method is being added to' \
|
88
|
-
"add_method(:#{method}).to(instance)"
|
89
|
-
end
|
90
|
-
|
91
|
-
context 'when not calling to' do
|
92
|
-
it 'raises error' do
|
93
|
-
expect { expectation }.to raise_error(
|
94
|
-
SyntaxError, expected_error
|
95
|
-
)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Sinclair::MethodDefinition do
|
6
|
-
describe 'yard' do
|
7
|
-
describe '#build' do
|
8
|
-
describe 'using string method with no options' do
|
9
|
-
subject(:method_definition) do
|
10
|
-
described_class.from(name, code)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:klass) { Class.new }
|
14
|
-
let(:instance) { klass.new }
|
15
|
-
let(:code) { '@x = @x.to_i ** 2 + 1' }
|
16
|
-
let(:name) { :sequence }
|
17
|
-
|
18
|
-
it 'adds a dynamic method' do
|
19
|
-
expect { method_definition.build(klass) }.to add_method(name).to(instance)
|
20
|
-
expect { instance.sequence }
|
21
|
-
.to change { instance.instance_variable_get(:@x) }.from(nil).to 1
|
22
|
-
expect(instance.sequence).to eq(2)
|
23
|
-
expect(instance.sequence).to eq(5)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'changes instance variable' do
|
27
|
-
method_definition.build(klass)
|
28
|
-
|
29
|
-
expect { instance.sequence }
|
30
|
-
.to change { instance.instance_variable_get(:@x) }
|
31
|
-
.from(nil).to 1
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'using block with cache option' do
|
36
|
-
subject(:method_definition) do
|
37
|
-
described_class.from(name, cached: true) do
|
38
|
-
@x = @x.to_i**2 + 1
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
let(:klass) { Class.new }
|
43
|
-
let(:instance) { klass.new }
|
44
|
-
let(:name) { :sequence }
|
45
|
-
|
46
|
-
it 'adds a dynamic method' do
|
47
|
-
expect { method_definition.build(klass) }.to add_method(name).to(instance)
|
48
|
-
expect { instance.sequence }
|
49
|
-
.to change { instance.instance_variable_get(:@x) }.from(nil).to 1
|
50
|
-
expect { instance.sequence }.not_to change(instance, :sequence)
|
51
|
-
expect(instance.instance_variable_get(:@sequence)).to eq(1)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|