Class: CodeDrivenDevelopment::Rule::BooleanOr
Instance Method Summary
collapse
#initialize
Instance Method Details
#capable? ⇒ Boolean
4
5
6
7
8
|
# File 'lib/code_driven_development/rule/boolean_or.rb', line 4
def capable?
code.sexp_type == :or &&
left.sexp_type == :call &&
right.sexp_type == :call
end
|
#test ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/code_driven_development/rule/boolean_or.rb', line 10
def test
left_is_true_context = TestComponent::Context.new(%Q("##{left_method_name} is truthy"))
right_is_true_context = TestComponent::Context.new(%Q("##{left_method_name} is falsey"))
left_is_true_context.befores << "allow(obj).to receive(:#{left_method_name}).and_return('#{left_method_name}')"
left_is_true_context.befores << "allow(obj).to receive(:#{right_method_name})"
left_is_true_context << TestComponent::Test.new("returns ##{left_method_name}", [
"expect(subject).to eq '#{left_method_name}'"
])
left_is_true_context << TestComponent::Test.new("doesn't call ##{right_method_name}", [
"subject",
"expect(obj).not_to have_received :#{right_method_name}"
])
right_is_true_context.befores << "allow(obj).to receive(:#{left_method_name}).and_return(false)"
right_is_true_context.befores << "allow(obj).to receive(:#{right_method_name}).and_return('#{right_method_name}')"
right_is_true_context << TestComponent::Test.new("returns ##{right_method_name}", [
"expect(subject).to eq '#{right_method_name}'"
])
right_is_true_context << TestComponent::Test.new("calls ##{left_method_name}", [
"subject",
"expect(obj).to have_received :#{left_method_name}"
])
test_context << left_is_true_context
test_context << right_is_true_context
end
|