sinclair 1.6.2 → 1.6.7

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +37 -2
  3. data/Dockerfile +2 -2
  4. data/README.md +6 -2
  5. data/config/check_specs.yml +3 -0
  6. data/config/yardstick.yml +8 -1
  7. data/lib/sinclair/matchers.rb +37 -10
  8. data/lib/sinclair/matchers/add_class_method.rb +16 -13
  9. data/lib/sinclair/matchers/add_class_method_to.rb +9 -23
  10. data/lib/sinclair/matchers/add_instance_method.rb +16 -18
  11. data/lib/sinclair/matchers/add_instance_method_to.rb +12 -16
  12. data/lib/sinclair/matchers/add_method.rb +13 -30
  13. data/lib/sinclair/matchers/add_method_to.rb +4 -56
  14. data/lib/sinclair/matchers/base.rb +45 -0
  15. data/lib/sinclair/matchers/change_class_method.rb +42 -0
  16. data/lib/sinclair/matchers/change_class_method_on.rb +64 -0
  17. data/lib/sinclair/matchers/change_instance_method.rb +42 -0
  18. data/lib/sinclair/matchers/change_instance_method_on.rb +98 -0
  19. data/lib/sinclair/matchers/change_method_on.rb +25 -0
  20. data/lib/sinclair/matchers/method_to.rb +82 -0
  21. data/lib/sinclair/options.rb +47 -46
  22. data/lib/sinclair/options/builder.rb +1 -1
  23. data/lib/sinclair/options/class_methods.rb +99 -0
  24. data/lib/sinclair/version.rb +1 -1
  25. data/spec/integration/readme/sinclair/options_spec.rb +8 -0
  26. data/spec/integration/yard/sinclair/options_parser_spec.rb +9 -0
  27. data/spec/integration/yard/sinclair/options_spec.rb +17 -6
  28. data/spec/lib/sinclair/matchers/add_class_method_to_spec.rb +40 -16
  29. data/spec/lib/sinclair/matchers/add_instance_method_to_spec.rb +36 -12
  30. data/spec/lib/sinclair/matchers/change_class_method_on_spec.rb +138 -0
  31. data/spec/lib/sinclair/matchers/change_class_method_spec.rb +38 -0
  32. data/spec/lib/sinclair/matchers/change_instance_method_on_spec.rb +149 -0
  33. data/spec/lib/sinclair/matchers/change_instance_method_spec.rb +38 -0
  34. data/spec/lib/sinclair/matchers_spec.rb +30 -0
  35. data/spec/lib/sinclair/options/builder_spec.rb +16 -8
  36. data/spec/lib/sinclair/options/class_methods_spec.rb +255 -0
  37. data/spec/lib/sinclair/options_spec.rb +90 -78
  38. data/spec/support/models/builder_options.rb +7 -0
  39. data/spec/support/models/open_options.rb +7 -0
  40. metadata +17 -2
@@ -14,22 +14,46 @@ describe Sinclair::Matchers::AddInstanceMethodTo do
14
14
  proc { klass.send(:define_method, method) {} }
15
15
  end
16
16
 
17
- context 'when a method is added' do
18
- it { expect(matcher).to be_matches(event_proc) }
19
- end
17
+ context 'when class does not have the method yet' do
18
+ context 'when a method is added' do
19
+ it { expect(matcher).to be_matches(event_proc) }
20
+ end
20
21
 
21
- context 'when a method is not added' do
22
- let(:event_proc) { proc {} }
22
+ context 'when a method is not added' do
23
+ let(:event_proc) { proc {} }
23
24
 
24
- it { expect(matcher).not_to be_matches(event_proc) }
25
- end
25
+ it { expect(matcher).not_to be_matches(event_proc) }
26
+ end
27
+
28
+ context 'when the wrong method is added' do
29
+ let(:event_proc) do
30
+ proc { klass.send(:define_method, :another_method) {} }
31
+ end
32
+
33
+ it { expect(matcher).not_to be_matches(event_proc) }
34
+ end
35
+
36
+ context 'when method already existed' do
37
+ before { event_proc.call }
38
+
39
+ it { expect(matcher).not_to be_matches(event_proc) }
40
+ end
26
41
 
27
- context 'when the wrong method is added' do
28
- let(:event_proc) do
29
- proc { klass.send(:define_method, :another_method) {} }
42
+ context 'when method is added to the class' do
43
+ let(:event_proc) do
44
+ proc { klass.send(:define_singleton_method, method) {} }
45
+ end
46
+
47
+ it { expect(matcher).not_to be_matches(event_proc) }
30
48
  end
49
+ end
31
50
 
32
- it { expect(matcher).not_to be_matches(event_proc) }
51
+ context 'when class already has the method' do
52
+ before { klass.send(:define_method, method) {} }
53
+
54
+ context 'when a method is changed' do
55
+ it { expect(matcher).not_to be_matches(event_proc) }
56
+ end
33
57
  end
34
58
 
35
59
  context 'when initializing with class' do
@@ -45,7 +69,7 @@ describe Sinclair::Matchers::AddInstanceMethodTo do
45
69
  expect { matcher.matches?(event_proc) { 1 } }
46
70
  .to raise_error(
47
71
  SyntaxError, 'Block not received by the `add_instance_method_to` matcher. ' \
48
- 'Perhaps you want to use `{ ... }` instead of do/end?'
72
+ 'Perhaps you want to use `{ ... }` instead of do/end?'
49
73
  )
50
74
  end
51
75
  end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Sinclair::Matchers::ChangeClassMethodOn do
6
+ subject(:matcher) { described_class.new(klass, method) }
7
+
8
+ let(:method) { :the_method }
9
+ let(:klass) { Class.new }
10
+
11
+ describe '#matches?' do
12
+ let(:event_proc) do
13
+ proc { klass.send(:define_singleton_method, method) {} }
14
+ end
15
+
16
+ context 'when class has the method' do
17
+ before { klass.send(:define_singleton_method, method) {} }
18
+
19
+ context 'when a method is changed' do
20
+ it { expect(matcher).to be_matches(event_proc) }
21
+ end
22
+
23
+ context 'when a method is not changed' do
24
+ let(:event_proc) { proc {} }
25
+
26
+ it { expect(matcher).not_to be_matches(event_proc) }
27
+ end
28
+
29
+ context 'when the wrong method is changed' do
30
+ let(:event_proc) do
31
+ proc { klass.send(:define_singleton_method, :another_method) {} }
32
+ end
33
+
34
+ it { expect(matcher).not_to be_matches(event_proc) }
35
+ end
36
+
37
+ context 'when method is changed on the class' do
38
+ let(:event_proc) do
39
+ proc { klass.send(:define_method, method) {} }
40
+ end
41
+
42
+ it { expect(matcher).not_to be_matches(event_proc) }
43
+ end
44
+ end
45
+
46
+ context 'when class does not have the method' do
47
+ context 'when a method is added' do
48
+ it { expect(matcher).not_to be_matches(event_proc) }
49
+ end
50
+ end
51
+
52
+ context 'when a block is given' do
53
+ it do
54
+ expect { matcher.matches?(event_proc) { 1 } }
55
+ .to raise_error(
56
+ SyntaxError, 'Block not received by the `change_class_method_on` matcher. ' \
57
+ 'Perhaps you want to use `{ ... }` instead of do/end?'
58
+ )
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#failure_message_for_should' do
64
+ context 'when method already exited' do
65
+ before do
66
+ klass.send(:define_singleton_method, method) {}
67
+ matcher.matches?(proc {})
68
+ end
69
+
70
+ it 'returns information on the instance class and method' do
71
+ expect(matcher.failure_message_for_should)
72
+ .to eq("expected class method '#{method}' to be changed on #{klass} but it didn't")
73
+ end
74
+ end
75
+
76
+ context 'when method did not exite' do
77
+ it 'returns information on the instance class and method' do
78
+ expect(matcher.failure_message_for_should)
79
+ .to eq("expected class method '#{method}' to be changed on #{klass} but it didn't exist")
80
+ end
81
+ end
82
+
83
+ context 'when initializing with class and method already existed' do
84
+ subject(:matcher) { described_class.new(klass, method) }
85
+
86
+ before do
87
+ klass.send(:define_singleton_method, method) {}
88
+ matcher.matches?(proc {})
89
+ end
90
+
91
+ it 'returns information on the instance class and method' do
92
+ expect(matcher.failure_message_for_should)
93
+ .to eq("expected class method '#{method}' to be changed on #{klass} but it didn't")
94
+ end
95
+ end
96
+
97
+ context 'when initializing with class and method didnt exist' do
98
+ subject(:matcher) { described_class.new(klass, method) }
99
+
100
+ it 'returns information on the instance class and method' do
101
+ expect(matcher.failure_message_for_should)
102
+ .to eq("expected class method '#{method}' to be changed on #{klass} but it didn't exist")
103
+ end
104
+ end
105
+ end
106
+
107
+ describe '#failure_message_for_should_not' do
108
+ it 'returns information on the instance class and method' do
109
+ expect(matcher.failure_message_for_should_not)
110
+ .to eq("expected class method '#{method}' not to be changed on #{klass} but it was")
111
+ end
112
+
113
+ context 'when initializing with class' do
114
+ subject(:matcher) { described_class.new(klass, method) }
115
+
116
+ it 'returns information on the instance class and method' do
117
+ expect(matcher.failure_message_for_should_not)
118
+ .to eq("expected class method '#{method}' not to be changed on #{klass} but it was")
119
+ end
120
+ end
121
+ end
122
+
123
+ describe 'description' do
124
+ it 'returns information on the instance class and method' do
125
+ expect(matcher.description)
126
+ .to eq("change class method '#{method}' on #{klass}")
127
+ end
128
+
129
+ context 'when initializing with class' do
130
+ subject(:matcher) { described_class.new(klass, method) }
131
+
132
+ it 'returns information on the instance class and method' do
133
+ expect(matcher.description)
134
+ .to eq("change class method '#{method}' on #{klass}")
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Sinclair::Matchers::ChangeClassMethod do
6
+ subject(:matcher) { described_class.new(method) }
7
+
8
+ let(:method) { :the_method }
9
+ let(:klass) { Class.new }
10
+
11
+ describe '#on' do
12
+ it do
13
+ expect(matcher.on(klass.new))
14
+ .to be_a(Sinclair::Matchers::ChangeClassMethodOn)
15
+ end
16
+
17
+ it 'returns an add_class_method_to' do
18
+ expect(matcher.on(klass))
19
+ .to eq(Sinclair::Matchers::ChangeClassMethodOn.new(klass, method))
20
+ end
21
+ end
22
+
23
+ describe '#matches?' do
24
+ it do
25
+ expect { matcher.matches?(proc {}) }
26
+ .to raise_error(
27
+ SyntaxError, 'You should specify which class the method is being changed on' \
28
+ "change_class_method(:#{method}).on(klass)"
29
+ )
30
+ end
31
+ end
32
+
33
+ describe '#supports_block_expectations?' do
34
+ it do
35
+ expect(matcher).to be_supports_block_expectations
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Sinclair::Matchers::ChangeInstanceMethodOn do
6
+ subject(:matcher) { described_class.new(instance, method) }
7
+
8
+ let(:method) { :the_method }
9
+ let(:klass) { Class.new }
10
+ let(:instance) { klass.new }
11
+
12
+ describe '#matches?' do
13
+ let(:event_proc) do
14
+ proc { klass.send(:define_method, method) {} }
15
+ end
16
+
17
+ context 'when class has the method' do
18
+ before { klass.send(:define_method, method) {} }
19
+
20
+ context 'when a method is changed' do
21
+ it { expect(matcher).to be_matches(event_proc) }
22
+ end
23
+
24
+ context 'when a method is not changed' do
25
+ let(:event_proc) { proc {} }
26
+
27
+ it { expect(matcher).not_to be_matches(event_proc) }
28
+ end
29
+
30
+ context 'when the wrong method is changed' do
31
+ let(:event_proc) do
32
+ proc { klass.send(:define_method, :another_method) {} }
33
+ end
34
+
35
+ it { expect(matcher).not_to be_matches(event_proc) }
36
+ end
37
+
38
+ context 'when method is changed on the class' do
39
+ let(:event_proc) do
40
+ proc { klass.send(:define_singleton_method, method) {} }
41
+ end
42
+
43
+ it { expect(matcher).not_to be_matches(event_proc) }
44
+ end
45
+ end
46
+
47
+ context 'when class does not have the method' do
48
+ context 'when a method is added' do
49
+ it { expect(matcher).not_to be_matches(event_proc) }
50
+ end
51
+ end
52
+
53
+ context 'when initializing with class' do
54
+ subject(:matcher) { described_class.new(klass, method) }
55
+
56
+ before { klass.send(:define_method, method) {} }
57
+
58
+ context 'when a method is added' do
59
+ it { expect(matcher).to be_matches(event_proc) }
60
+ end
61
+ end
62
+
63
+ context 'when a block is given' do
64
+ it do
65
+ expect { matcher.matches?(event_proc) { 1 } }
66
+ .to raise_error(
67
+ SyntaxError, 'Block not received by the `change_instance_method_on` matcher. ' \
68
+ 'Perhaps you want to use `{ ... }` instead of do/end?'
69
+ )
70
+ end
71
+ end
72
+ end
73
+
74
+ describe '#failure_message_for_should' do
75
+ context 'when method already exited' do
76
+ before do
77
+ klass.send(:define_method, method) {}
78
+ matcher.matches?(proc {})
79
+ end
80
+
81
+ it 'returns information on the instance class and method' do
82
+ expect(matcher.failure_message_for_should)
83
+ .to eq("expected '#{method}' to be changed on #{klass} but it didn't")
84
+ end
85
+ end
86
+
87
+ context 'when method did not exite' do
88
+ it 'returns information on the instance class and method' do
89
+ expect(matcher.failure_message_for_should)
90
+ .to eq("expected '#{method}' to be changed on #{klass} but it didn't exist")
91
+ end
92
+ end
93
+
94
+ context 'when initializing with class and method already existed' do
95
+ subject(:matcher) { described_class.new(klass, method) }
96
+
97
+ before do
98
+ klass.send(:define_method, method) {}
99
+ matcher.matches?(proc {})
100
+ end
101
+
102
+ it 'returns information on the instance class and method' do
103
+ expect(matcher.failure_message_for_should)
104
+ .to eq("expected '#{method}' to be changed on #{klass} but it didn't")
105
+ end
106
+ end
107
+
108
+ context 'when initializing with class and method didnt exist' do
109
+ subject(:matcher) { described_class.new(klass, method) }
110
+
111
+ it 'returns information on the instance class and method' do
112
+ expect(matcher.failure_message_for_should)
113
+ .to eq("expected '#{method}' to be changed on #{klass} but it didn't exist")
114
+ end
115
+ end
116
+ end
117
+
118
+ describe '#failure_message_for_should_not' do
119
+ it 'returns information on the instance class and method' do
120
+ expect(matcher.failure_message_for_should_not)
121
+ .to eq("expected '#{method}' not to be changed on #{klass} but it was")
122
+ end
123
+
124
+ context 'when initializing with class' do
125
+ subject(:matcher) { described_class.new(klass, method) }
126
+
127
+ it 'returns information on the instance class and method' do
128
+ expect(matcher.failure_message_for_should_not)
129
+ .to eq("expected '#{method}' not to be changed on #{klass} but it was")
130
+ end
131
+ end
132
+ end
133
+
134
+ describe 'description' do
135
+ it 'returns information on the instance class and method' do
136
+ expect(matcher.description)
137
+ .to eq("change method '#{method}' on #{klass} instances")
138
+ end
139
+
140
+ context 'when initializing with class' do
141
+ subject(:matcher) { described_class.new(klass, method) }
142
+
143
+ it 'returns information on the instance class and method' do
144
+ expect(matcher.description)
145
+ .to eq("change method '#{method}' on #{klass} instances")
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Sinclair::Matchers::ChangeInstanceMethod do
6
+ subject(:matcher) { described_class.new(method) }
7
+
8
+ let(:method) { :the_method }
9
+ let(:klass) { Class.new }
10
+ let(:instance) { klass.new }
11
+
12
+ describe '#on' do
13
+ it do
14
+ expect(matcher.on(klass.new)).to be_a(Sinclair::Matchers::ChangeInstanceMethodOn)
15
+ end
16
+
17
+ it 'returns an change_instance_method_on' do
18
+ expect(matcher.on(instance))
19
+ .to eq(Sinclair::Matchers::ChangeInstanceMethodOn.new(instance, method))
20
+ end
21
+ end
22
+
23
+ describe '#matches?' do
24
+ it do
25
+ expect { matcher.matches?(proc {}) }
26
+ .to raise_error(
27
+ SyntaxError, 'You should specify which instance the method is being changed on' \
28
+ "change_method(:#{method}).on(instance)"
29
+ )
30
+ end
31
+ end
32
+
33
+ describe '#supports_block_expectations?' do
34
+ it do
35
+ expect(matcher).to be_supports_block_expectations
36
+ end
37
+ end
38
+ end
@@ -31,4 +31,34 @@ describe Sinclair::Matchers do
31
31
  .to eq(described_class::AddClassMethod.new(:method_name))
32
32
  end
33
33
  end
34
+
35
+ describe '#change_method' do
36
+ it 'has been added to DSL' do
37
+ expect(respond_to?(:change_method)).to be_truthy
38
+ end
39
+
40
+ it do
41
+ expect(change_method(:method_name)).to be_a(described_class::ChangeInstanceMethod)
42
+ end
43
+
44
+ it 'returns the matcher with correct argument' do
45
+ expect(change_method(:method_name))
46
+ .to eq(described_class::ChangeInstanceMethod.new(:method_name))
47
+ end
48
+ end
49
+
50
+ describe '#change_class_method' do
51
+ it 'has been added to DSL' do
52
+ expect(respond_to?(:change_class_method)).to be_truthy
53
+ end
54
+
55
+ it do
56
+ expect(change_class_method(:method_name)).to be_a(described_class::ChangeClassMethod)
57
+ end
58
+
59
+ it 'returns the matcher with correct argument' do
60
+ expect(change_class_method(:method_name))
61
+ .to eq(described_class::ChangeClassMethod.new(:method_name))
62
+ end
63
+ end
34
64
  end