mutant 0.8.24 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -3
- data/Changelog.md +14 -654
- data/Gemfile +13 -0
- data/Gemfile.lock +59 -64
- data/LICENSE +271 -20
- data/README.md +73 -140
- data/Rakefile +0 -21
- data/bin/mutant +7 -2
- data/config/reek.yml +2 -1
- data/config/rubocop.yml +5 -9
- data/docs/incremental.md +76 -0
- data/docs/known-problems.md +0 -14
- data/docs/mutant-minitest.md +1 -1
- data/docs/mutant-rspec.md +2 -24
- data/lib/mutant.rb +45 -53
- data/lib/mutant/ast/nodes.rb +0 -2
- data/lib/mutant/ast/types.rb +1 -117
- data/lib/mutant/base.rb +192 -0
- data/lib/mutant/bootstrap.rb +145 -0
- data/lib/mutant/cli.rb +68 -54
- data/lib/mutant/config.rb +119 -6
- data/lib/mutant/env.rb +94 -8
- data/lib/mutant/expression.rb +6 -1
- data/lib/mutant/expression/parser.rb +9 -31
- data/lib/mutant/integration.rb +64 -36
- data/lib/mutant/isolation.rb +16 -1
- data/lib/mutant/isolation/fork.rb +105 -40
- data/lib/mutant/license.rb +34 -0
- data/lib/mutant/license/subscription.rb +47 -0
- data/lib/mutant/license/subscription/commercial.rb +57 -0
- data/lib/mutant/license/subscription/opensource.rb +77 -0
- data/lib/mutant/loader.rb +27 -4
- data/lib/mutant/matcher.rb +48 -1
- data/lib/mutant/matcher/chain.rb +1 -1
- data/lib/mutant/matcher/config.rb +0 -2
- data/lib/mutant/matcher/filter.rb +1 -1
- data/lib/mutant/matcher/method.rb +11 -7
- data/lib/mutant/matcher/methods.rb +1 -1
- data/lib/mutant/matcher/namespace.rb +1 -1
- data/lib/mutant/matcher/null.rb +1 -1
- data/lib/mutant/matcher/scope.rb +1 -1
- data/lib/mutant/meta/example/dsl.rb +0 -8
- data/lib/mutant/mutation.rb +1 -2
- data/lib/mutant/mutator/node.rb +2 -9
- data/lib/mutant/mutator/node/arguments.rb +1 -1
- data/lib/mutant/mutator/node/class.rb +0 -8
- data/lib/mutant/mutator/node/define.rb +0 -12
- data/lib/mutant/mutator/node/generic.rb +30 -44
- data/lib/mutant/mutator/node/index.rb +4 -4
- data/lib/mutant/mutator/node/literal/regex.rb +0 -39
- data/lib/mutant/mutator/node/send.rb +13 -12
- data/lib/mutant/parallel.rb +61 -40
- data/lib/mutant/parallel/driver.rb +59 -0
- data/lib/mutant/parallel/source.rb +6 -2
- data/lib/mutant/parallel/worker.rb +63 -45
- data/lib/mutant/range.rb +15 -0
- data/lib/mutant/reporter/cli.rb +5 -11
- data/lib/mutant/reporter/cli/format.rb +3 -46
- data/lib/mutant/reporter/cli/printer/config.rb +5 -6
- data/lib/mutant/reporter/cli/printer/env.rb +40 -0
- data/lib/mutant/reporter/cli/printer/env_progress.rb +13 -17
- data/lib/mutant/reporter/cli/printer/isolation_result.rb +17 -3
- data/lib/mutant/reporter/cli/printer/mutation_result.rb +2 -3
- data/lib/mutant/reporter/cli/printer/status_progressive.rb +19 -10
- data/lib/mutant/repository.rb +0 -65
- data/lib/mutant/repository/diff.rb +104 -0
- data/lib/mutant/repository/diff/ranges.rb +52 -0
- data/lib/mutant/result.rb +16 -7
- data/lib/mutant/runner.rb +38 -47
- data/lib/mutant/runner/sink.rb +1 -1
- data/lib/mutant/selector/null.rb +19 -0
- data/lib/mutant/subject.rb +3 -1
- data/lib/mutant/subject/method/instance.rb +3 -1
- data/lib/mutant/transform.rb +511 -0
- data/lib/mutant/variable.rb +282 -0
- data/lib/mutant/version.rb +1 -1
- data/lib/mutant/warnings.rb +113 -0
- data/meta/case.rb +1 -0
- data/meta/class.rb +0 -9
- data/meta/def.rb +1 -26
- data/meta/regexp.rb +10 -20
- data/meta/send.rb +14 -46
- data/mutant-minitest.gemspec +1 -1
- data/mutant-rspec.gemspec +2 -2
- data/mutant.gemspec +15 -16
- data/mutant.yml +6 -0
- data/spec/integration/mutant/isolation/fork_spec.rb +22 -5
- data/spec/integration/mutant/minitest_spec.rb +3 -2
- data/spec/integration/mutant/rspec_spec.rb +4 -3
- data/spec/integrations.yml +16 -13
- data/spec/shared/base_behavior.rb +45 -0
- data/spec/shared/framework_integration_behavior.rb +43 -14
- data/spec/spec_helper.rb +21 -17
- data/spec/support/corpus.rb +56 -95
- data/spec/support/shared_context.rb +37 -14
- data/spec/support/xspec.rb +7 -3
- data/spec/unit/mutant/bootstrap_spec.rb +216 -0
- data/spec/unit/mutant/cli_spec.rb +173 -117
- data/spec/unit/mutant/config_spec.rb +126 -0
- data/spec/unit/mutant/either_spec.rb +247 -0
- data/spec/unit/mutant/env_spec.rb +162 -40
- data/spec/unit/mutant/expression/method_spec.rb +16 -0
- data/spec/unit/mutant/expression/parser_spec.rb +29 -33
- data/spec/unit/mutant/expression_spec.rb +5 -7
- data/spec/unit/mutant/integration_spec.rb +100 -9
- data/spec/unit/mutant/isolation/fork_spec.rb +125 -67
- data/spec/unit/mutant/isolation/result_spec.rb +33 -1
- data/spec/unit/mutant/license_spec.rb +257 -0
- data/spec/unit/mutant/loader_spec.rb +50 -11
- data/spec/unit/mutant/matcher/compiler_spec.rb +0 -78
- data/spec/unit/mutant/matcher/method/instance_spec.rb +55 -11
- data/spec/unit/mutant/matcher/method/singleton_spec.rb +12 -2
- data/spec/unit/mutant/matcher_spec.rb +102 -0
- data/spec/unit/mutant/maybe_spec.rb +60 -0
- data/spec/unit/mutant/meta/example/dsl_spec.rb +1 -17
- data/spec/unit/mutant/mutation_spec.rb +13 -6
- data/spec/unit/mutant/parallel/driver_spec.rb +112 -14
- data/spec/unit/mutant/parallel/source/array_spec.rb +25 -17
- data/spec/unit/mutant/parallel/worker_spec.rb +182 -44
- data/spec/unit/mutant/parallel_spec.rb +105 -8
- data/spec/unit/mutant/range_spec.rb +141 -0
- data/spec/unit/mutant/reporter/cli/printer/config_spec.rb +7 -21
- data/spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb +15 -6
- data/spec/unit/mutant/reporter/cli/printer/env_result_spec.rb +10 -2
- data/spec/unit/mutant/reporter/cli/printer/isolation_result_spec.rb +12 -4
- data/spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb +31 -2
- data/spec/unit/mutant/reporter/cli/printer/status_progressive_spec.rb +4 -4
- data/spec/unit/mutant/reporter/cli/printer/subject_result_spec.rb +5 -0
- data/spec/unit/mutant/reporter/cli_spec.rb +46 -123
- data/spec/unit/mutant/repository/diff/ranges_spec.rb +180 -0
- data/spec/unit/mutant/repository/diff_spec.rb +84 -71
- data/spec/unit/mutant/require_highjack_spec.rb +1 -1
- data/spec/unit/mutant/result/env_spec.rb +39 -9
- data/spec/unit/mutant/result/test_spec.rb +14 -0
- data/spec/unit/mutant/runner_spec.rb +88 -41
- data/spec/unit/mutant/selector/expression_spec.rb +11 -10
- data/spec/unit/mutant/selector/null_spec.rb +17 -0
- data/spec/unit/mutant/subject/method/instance_spec.rb +44 -5
- data/spec/unit/mutant/subject/method/singleton_spec.rb +9 -2
- data/spec/unit/mutant/subject_spec.rb +9 -1
- data/spec/unit/mutant/transform/array_spec.rb +92 -0
- data/spec/unit/mutant/transform/bool_spec.rb +63 -0
- data/spec/unit/mutant/transform/error_spec.rb +132 -0
- data/spec/unit/mutant/transform/exception_spec.rb +44 -0
- data/spec/unit/mutant/transform/hash_spec.rb +236 -0
- data/spec/unit/mutant/transform/index_spec.rb +92 -0
- data/spec/unit/mutant/transform/named_spec.rb +49 -0
- data/spec/unit/mutant/transform/primitive_spec.rb +56 -0
- data/spec/unit/mutant/transform/sequence_spec.rb +98 -0
- data/spec/unit/mutant/variable_spec.rb +618 -0
- data/spec/unit/mutant/warnings_spec.rb +89 -0
- data/spec/unit/mutant/world_spec.rb +63 -0
- data/test_app/Gemfile.minitest +0 -2
- metadata +79 -113
- data/.gitattributes +0 -1
- data/.ruby-gemset +0 -1
- data/config/triage.yml +0 -2
- data/lib/mutant/actor.rb +0 -57
- data/lib/mutant/actor/env.rb +0 -31
- data/lib/mutant/actor/mailbox.rb +0 -34
- data/lib/mutant/actor/receiver.rb +0 -42
- data/lib/mutant/actor/sender.rb +0 -26
- data/lib/mutant/ast/meta/restarg.rb +0 -19
- data/lib/mutant/ast/regexp.rb +0 -42
- data/lib/mutant/ast/regexp/transformer.rb +0 -187
- data/lib/mutant/ast/regexp/transformer/direct.rb +0 -123
- data/lib/mutant/ast/regexp/transformer/named_group.rb +0 -59
- data/lib/mutant/ast/regexp/transformer/options_group.rb +0 -83
- data/lib/mutant/ast/regexp/transformer/quantifier.rb +0 -114
- data/lib/mutant/ast/regexp/transformer/recursive.rb +0 -58
- data/lib/mutant/ast/regexp/transformer/root.rb +0 -31
- data/lib/mutant/ast/regexp/transformer/text.rb +0 -60
- data/lib/mutant/env/bootstrap.rb +0 -160
- data/lib/mutant/matcher/compiler.rb +0 -60
- data/lib/mutant/mutator/node/regexp.rb +0 -35
- data/lib/mutant/mutator/node/regexp/alternation_meta.rb +0 -23
- data/lib/mutant/mutator/node/regexp/capture_group.rb +0 -28
- data/lib/mutant/mutator/node/regexp/character_type.rb +0 -32
- data/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb +0 -23
- data/lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb +0 -23
- data/lib/mutant/mutator/node/regexp/greedy_zero_or_more.rb +0 -27
- data/lib/mutant/parallel/master.rb +0 -181
- data/lib/mutant/reporter/cli/printer/status.rb +0 -53
- data/lib/mutant/reporter/cli/tput.rb +0 -46
- data/lib/mutant/warning_filter.rb +0 -61
- data/meta/regexp/character_types.rb +0 -23
- data/meta/regexp/regexp_alternation_meta.rb +0 -13
- data/meta/regexp/regexp_bol_anchor.rb +0 -10
- data/meta/regexp/regexp_bos_anchor.rb +0 -18
- data/meta/regexp/regexp_capture_group.rb +0 -19
- data/meta/regexp/regexp_eol_anchor.rb +0 -10
- data/meta/regexp/regexp_eos_anchor.rb +0 -8
- data/meta/regexp/regexp_eos_ob_eol_anchor.rb +0 -10
- data/meta/regexp/regexp_greedy_zero_or_more.rb +0 -12
- data/meta/regexp/regexp_root_expression.rb +0 -10
- data/meta/restarg.rb +0 -10
- data/spec/support/fake_actor.rb +0 -111
- data/spec/support/warning.rb +0 -66
- data/spec/unit/mutant/actor/binding_spec.rb +0 -34
- data/spec/unit/mutant/actor/env_spec.rb +0 -31
- data/spec/unit/mutant/actor/mailbox_spec.rb +0 -28
- data/spec/unit/mutant/actor/message_spec.rb +0 -25
- data/spec/unit/mutant/actor/receiver_spec.rb +0 -58
- data/spec/unit/mutant/actor/sender_spec.rb +0 -24
- data/spec/unit/mutant/ast/regexp/parse_spec.rb +0 -19
- data/spec/unit/mutant/ast/regexp/transformer/lookup_table/table_spec.rb +0 -21
- data/spec/unit/mutant/ast/regexp/transformer/lookup_table_spec.rb +0 -35
- data/spec/unit/mutant/ast/regexp/transformer_spec.rb +0 -21
- data/spec/unit/mutant/ast/regexp_spec.rb +0 -704
- data/spec/unit/mutant/env/bootstrap_spec.rb +0 -188
- data/spec/unit/mutant/matcher/compiler/subject_prefix_spec.rb +0 -26
- data/spec/unit/mutant/parallel/master_spec.rb +0 -338
- data/spec/unit/mutant/reporter/cli/printer/status_spec.rb +0 -121
- data/spec/unit/mutant/reporter/cli/tput_spec.rb +0 -50
- data/spec/unit/mutant/warning_filter_spec.rb +0 -106
- data/spec/unit/mutant_spec.rb +0 -17
- data/test_app/Gemfile.rspec3.7 +0 -7
data/meta/restarg.rb
DELETED
data/spec/support/fake_actor.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'mutant/actor'
|
4
|
-
|
5
|
-
# A fake actor used from specs
|
6
|
-
module FakeActor
|
7
|
-
class Expectation
|
8
|
-
include Concord::Public.new(:name, :message, :block)
|
9
|
-
include Equalizer.new(:name, :message)
|
10
|
-
|
11
|
-
def self.new(_name, _message, _block = nil)
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
def verify(other)
|
16
|
-
unless eql?(other)
|
17
|
-
fail "Got:\n#{other.inspect}\nExpected:\n#{inspect}"
|
18
|
-
end
|
19
|
-
block&.call(other.message)
|
20
|
-
end
|
21
|
-
end # Expectation
|
22
|
-
|
23
|
-
class MessageSequence
|
24
|
-
include Adamantium::Flat, Concord::Public.new(:messages)
|
25
|
-
|
26
|
-
def self.new
|
27
|
-
super([])
|
28
|
-
end
|
29
|
-
|
30
|
-
def add(name, *message_arguments, &block)
|
31
|
-
messages << Expectation.new(name, Mutant::Actor::Message.new(*message_arguments), block)
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def sending(expectation)
|
36
|
-
fail "Unexpected send: #{expectation.inspect}" if messages.empty?
|
37
|
-
expected = messages.shift
|
38
|
-
expected.verify(expectation)
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
def receiving(name)
|
43
|
-
fail "No message to read for #{name.inspect}" if messages.empty?
|
44
|
-
expected = messages.shift
|
45
|
-
fail "Unexpected message #{expected.inspect} for #{name.inspect}" unless expected.name.eql?(name)
|
46
|
-
expected.message
|
47
|
-
end
|
48
|
-
|
49
|
-
def consumed?
|
50
|
-
messages.empty?
|
51
|
-
end
|
52
|
-
end # MessageSequence
|
53
|
-
|
54
|
-
class Env
|
55
|
-
include Concord.new(:messages, :mailbox_names)
|
56
|
-
|
57
|
-
def spawn
|
58
|
-
mailbox = mailbox(next_name)
|
59
|
-
yield mailbox if block_given?
|
60
|
-
mailbox.sender
|
61
|
-
end
|
62
|
-
|
63
|
-
def mailbox(name)
|
64
|
-
Mailbox.new(name, @messages)
|
65
|
-
end
|
66
|
-
|
67
|
-
def new_mailbox
|
68
|
-
mailbox(:current)
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def next_name
|
74
|
-
@mailbox_names.shift.tap do |name|
|
75
|
-
name or fail 'Tried to spawn actor when no name available'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end # Env
|
79
|
-
|
80
|
-
class Mailbox
|
81
|
-
include Concord.new(:name, :messages)
|
82
|
-
|
83
|
-
def receiver
|
84
|
-
Receiver.new(name, messages)
|
85
|
-
end
|
86
|
-
|
87
|
-
def sender
|
88
|
-
Sender.new(name, messages)
|
89
|
-
end
|
90
|
-
|
91
|
-
def bind(sender)
|
92
|
-
Mutant::Actor::Binding.new(self, sender)
|
93
|
-
end
|
94
|
-
end # Mailbox
|
95
|
-
|
96
|
-
class Sender
|
97
|
-
include Concord.new(:name, :messages)
|
98
|
-
|
99
|
-
def call(message)
|
100
|
-
messages.sending(Expectation.new(name, message))
|
101
|
-
end
|
102
|
-
end # Sender
|
103
|
-
|
104
|
-
class Receiver
|
105
|
-
include Concord::Public.new(:name, :messages)
|
106
|
-
|
107
|
-
def call
|
108
|
-
messages.receiving(name)
|
109
|
-
end
|
110
|
-
end # Receiver
|
111
|
-
end # FakeActor
|
data/spec/support/warning.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'yaml'
|
4
|
-
require 'equalizer'
|
5
|
-
require 'memoizable'
|
6
|
-
require 'ice_nine'
|
7
|
-
|
8
|
-
module MutantSpec
|
9
|
-
class Warning
|
10
|
-
def self.assert_no_warnings
|
11
|
-
return if EXTRACTOR.warnings.empty?
|
12
|
-
|
13
|
-
fail UnexpectedWarnings, EXTRACTOR.warnings.to_a
|
14
|
-
end
|
15
|
-
|
16
|
-
class UnexpectedWarnings < StandardError
|
17
|
-
MSG = 'Unexpected warnings: %s'
|
18
|
-
|
19
|
-
def initialize(warnings)
|
20
|
-
super(MSG % warnings.join("\n"))
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Extractor < DelegateClass(IO)
|
25
|
-
PATTERN = /\A(?:.+):(?:\d+): warning: (?:.+)\n\z/.freeze
|
26
|
-
|
27
|
-
include Equalizer.new(:whitelist, :seen, :io), Memoizable
|
28
|
-
|
29
|
-
def initialize(io, whitelist)
|
30
|
-
@whitelist = whitelist
|
31
|
-
@seen = Set.new
|
32
|
-
@io = io
|
33
|
-
|
34
|
-
super(io)
|
35
|
-
end
|
36
|
-
|
37
|
-
def write(message)
|
38
|
-
return super if PATTERN !~ message
|
39
|
-
|
40
|
-
add(message.chomp)
|
41
|
-
|
42
|
-
self
|
43
|
-
end
|
44
|
-
|
45
|
-
def warnings
|
46
|
-
seen.dup
|
47
|
-
end
|
48
|
-
memoize :warnings
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def add(warning)
|
53
|
-
return if whitelist.any?(&warning.public_method(:end_with?))
|
54
|
-
|
55
|
-
seen << warning
|
56
|
-
end
|
57
|
-
|
58
|
-
attr_reader :whitelist, :seen, :io
|
59
|
-
end
|
60
|
-
|
61
|
-
warnings = Pathname.new(__dir__).join('warnings.yml').freeze
|
62
|
-
whitelist = IceNine.deep_freeze(YAML.load(warnings.read)) # rubocop:disable Security/YAMLLoad
|
63
|
-
|
64
|
-
EXTRACTOR = Extractor.new(STDERR, whitelist)
|
65
|
-
end
|
66
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Mutant::Actor::Binding do
|
4
|
-
let(:actor_a) { instance_double(Mutant::Actor::Mailbox, sender: sender_a, receiver: receiver_a) }
|
5
|
-
let(:sender_a) { instance_double(Mutant::Actor::Sender) }
|
6
|
-
let(:sender_b) { instance_double(Mutant::Actor::Sender) }
|
7
|
-
let(:receiver_a) { instance_double(Mutant::Actor::Receiver) }
|
8
|
-
let(:payload) { instance_double(Object) }
|
9
|
-
let(:type) { instance_double(Symbol) }
|
10
|
-
|
11
|
-
let(:object) { described_class.new(actor_a, sender_b) }
|
12
|
-
|
13
|
-
describe '#call' do
|
14
|
-
subject { object.call(type) }
|
15
|
-
|
16
|
-
before do
|
17
|
-
expect(sender_b).to receive(:call).with(message(type, sender_a)).ordered
|
18
|
-
expect(receiver_a).to receive(:call).ordered.and_return(message(response_type, payload))
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when return type equals request type' do
|
22
|
-
let(:response_type) { type }
|
23
|
-
it { should be(payload) }
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when return type NOT equals request type' do
|
27
|
-
let(:response_type) { double('Other Type') }
|
28
|
-
|
29
|
-
it 'raises error' do
|
30
|
-
expect { subject }.to raise_error(Mutant::Actor::ProtocolError, "Expected #{type} but got #{response_type}")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Mutant::Actor::Env do
|
4
|
-
let(:thread) { instance_double(Thread) }
|
5
|
-
let(:thread_root) { class_double(Thread) }
|
6
|
-
|
7
|
-
let(:object) { described_class.new(thread_root) }
|
8
|
-
|
9
|
-
describe '#spawn' do
|
10
|
-
subject { object.spawn(&block) }
|
11
|
-
|
12
|
-
let!(:mailbox) { Mutant::Actor::Mailbox.new }
|
13
|
-
|
14
|
-
let(:yields) { [] }
|
15
|
-
|
16
|
-
let(:block) { ->(actor) { yields << actor } }
|
17
|
-
|
18
|
-
before do
|
19
|
-
expect(Mutant::Actor::Mailbox).to receive(:new).and_return(mailbox).ordered
|
20
|
-
expect(thread_root).to receive(:new).and_yield.and_return(thread).ordered
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns sender' do
|
24
|
-
should be(mailbox.sender)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'yields actor' do
|
28
|
-
expect { subject }.to change { yields }.from([]).to([mailbox])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Mutant::Actor::Mailbox do
|
4
|
-
let(:mutex) { instance_double(Mutex) }
|
5
|
-
let(:condition_variable) { instance_double(ConditionVariable) }
|
6
|
-
|
7
|
-
before do
|
8
|
-
allow(Mutex).to receive(:new).and_return(mutex)
|
9
|
-
allow(ConditionVariable).to receive(:new).and_return(condition_variable)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '.new' do
|
13
|
-
subject { described_class.new }
|
14
|
-
|
15
|
-
its(:sender) { should eql(Mutant::Actor::Sender.new(condition_variable, mutex, [])) }
|
16
|
-
its(:receiver) { should eql(Mutant::Actor::Receiver.new(condition_variable, mutex, [])) }
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#bind' do
|
21
|
-
let(:object) { described_class.new }
|
22
|
-
let(:other) { instance_double(Mutant::Actor::Sender) }
|
23
|
-
|
24
|
-
subject { object.bind(other) }
|
25
|
-
|
26
|
-
it { should eql(Mutant::Actor::Binding.new(object, other)) }
|
27
|
-
end
|
28
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Mutant::Actor::Message do
|
4
|
-
|
5
|
-
let(:type) { instance_double(Symbol) }
|
6
|
-
let(:payload) { instance_double(Object) }
|
7
|
-
|
8
|
-
describe '.new' do
|
9
|
-
subject { described_class.new(*arguments) }
|
10
|
-
|
11
|
-
context 'with one argument' do
|
12
|
-
let(:arguments) { [type] }
|
13
|
-
|
14
|
-
its(:type) { should be(type) }
|
15
|
-
its(:payload) { should be(Mutant::Actor::Undefined) }
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with two arguments' do
|
19
|
-
let(:arguments) { [type, payload] }
|
20
|
-
|
21
|
-
its(:type) { should be(type) }
|
22
|
-
its(:payload) { should be(payload) }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Mutant::Actor::Receiver do
|
4
|
-
let(:messages) { instance_double(Array) }
|
5
|
-
let(:mutex) { instance_double(Mutex) }
|
6
|
-
let(:condition_variable) { instance_double(ConditionVariable) }
|
7
|
-
let(:message) { instance_double(Object) }
|
8
|
-
|
9
|
-
let(:object) { described_class.new(condition_variable, mutex, messages) }
|
10
|
-
|
11
|
-
describe '#call' do
|
12
|
-
subject { object.call }
|
13
|
-
|
14
|
-
context 'when messages contains a message' do
|
15
|
-
before do
|
16
|
-
expect(mutex).to receive(:synchronize).and_yield.ordered
|
17
|
-
expect(messages).to receive(:empty?).and_return(false).ordered
|
18
|
-
expect(messages).to receive(:shift).and_return(message).ordered
|
19
|
-
end
|
20
|
-
|
21
|
-
it { should be(message) }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when messages initially contains no message' do
|
25
|
-
before do
|
26
|
-
# 1rst failing try
|
27
|
-
expect(mutex).to receive(:synchronize).and_yield.ordered
|
28
|
-
expect(messages).to receive(:empty?).and_return(true).ordered
|
29
|
-
expect(condition_variable).to receive(:wait).with(mutex).ordered
|
30
|
-
# 2nd successful try
|
31
|
-
expect(mutex).to receive(:synchronize).and_yield.ordered
|
32
|
-
expect(messages).to receive(:empty?).and_return(false).ordered
|
33
|
-
expect(messages).to receive(:shift).and_return(message).ordered
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'waits for message' do
|
37
|
-
should be(message)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'when messages contains no message but thread gets waken without message arrived' do
|
42
|
-
before do
|
43
|
-
# 1rst failing try
|
44
|
-
expect(mutex).to receive(:synchronize).and_yield.ordered
|
45
|
-
expect(messages).to receive(:empty?).and_return(true).ordered
|
46
|
-
expect(condition_variable).to receive(:wait).with(mutex).ordered
|
47
|
-
# 2nd failing try
|
48
|
-
expect(mutex).to receive(:synchronize).and_yield.ordered
|
49
|
-
expect(messages).to receive(:empty?).and_return(true).ordered
|
50
|
-
expect(condition_variable).to receive(:wait).with(mutex).ordered
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'fails with error' do
|
54
|
-
expect { subject }.to raise_error(Mutant::Actor::ProtocolError)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Mutant::Actor::Sender do
|
4
|
-
let(:object) { described_class.new(condition_variable, mutex, messages) }
|
5
|
-
|
6
|
-
let(:condition_variable) { instance_double(ConditionVariable) }
|
7
|
-
let(:mutex) { instance_double(Mutex) }
|
8
|
-
let(:messages) { instance_double(Array) }
|
9
|
-
let(:type) { instance_double(Symbol) }
|
10
|
-
let(:payload) { instance_double(Object) }
|
11
|
-
let(:_message) { message(type, payload) }
|
12
|
-
|
13
|
-
describe '#call' do
|
14
|
-
subject { object.call(_message) }
|
15
|
-
|
16
|
-
before do
|
17
|
-
expect(mutex).to receive(:synchronize).ordered.and_yield
|
18
|
-
expect(messages).to receive(:<<).with(_message).ordered
|
19
|
-
expect(condition_variable).to receive(:signal).ordered
|
20
|
-
end
|
21
|
-
|
22
|
-
it_should_behave_like 'a command method'
|
23
|
-
end
|
24
|
-
end
|