rosette-core 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +26 -0
- data/History.txt +3 -0
- data/README.md +94 -0
- data/Rakefile +18 -0
- data/lib/rosette/core.rb +110 -0
- data/lib/rosette/core/branch_utils.rb +152 -0
- data/lib/rosette/core/commands.rb +139 -0
- data/lib/rosette/core/commands/errors.rb +17 -0
- data/lib/rosette/core/commands/git/commit_command.rb +65 -0
- data/lib/rosette/core/commands/git/diff_base_command.rb +301 -0
- data/lib/rosette/core/commands/git/diff_command.rb +188 -0
- data/lib/rosette/core/commands/git/diff_entry.rb +44 -0
- data/lib/rosette/core/commands/git/fetch_command.rb +27 -0
- data/lib/rosette/core/commands/git/repo_snapshot_command.rb +40 -0
- data/lib/rosette/core/commands/git/show_command.rb +70 -0
- data/lib/rosette/core/commands/git/snapshot_command.rb +50 -0
- data/lib/rosette/core/commands/git/status_command.rb +128 -0
- data/lib/rosette/core/commands/git/with_non_merge_ref.rb +48 -0
- data/lib/rosette/core/commands/git/with_ref.rb +92 -0
- data/lib/rosette/core/commands/git/with_refs.rb +92 -0
- data/lib/rosette/core/commands/git/with_repo_name.rb +50 -0
- data/lib/rosette/core/commands/git/with_snapshots.rb +45 -0
- data/lib/rosette/core/commands/queuing/enqueue_commit_command.rb +37 -0
- data/lib/rosette/core/commands/queuing/requeue_commit_command.rb +46 -0
- data/lib/rosette/core/commands/translations/export_command.rb +257 -0
- data/lib/rosette/core/commands/translations/translation_lookup_command.rb +66 -0
- data/lib/rosette/core/commands/translations/with_locale.rb +47 -0
- data/lib/rosette/core/configurator.rb +160 -0
- data/lib/rosette/core/error_reporters/buffered_error_reporter.rb +96 -0
- data/lib/rosette/core/error_reporters/error_reporter.rb +31 -0
- data/lib/rosette/core/error_reporters/nil_error_reporter.rb +25 -0
- data/lib/rosette/core/error_reporters/printing_error_reporter.rb +58 -0
- data/lib/rosette/core/error_reporters/raising_error_reporter.rb +27 -0
- data/lib/rosette/core/errors.rb +93 -0
- data/lib/rosette/core/extractor/commit_log.rb +33 -0
- data/lib/rosette/core/extractor/commit_log_status.rb +57 -0
- data/lib/rosette/core/extractor/commit_processor.rb +109 -0
- data/lib/rosette/core/extractor/extractor.rb +72 -0
- data/lib/rosette/core/extractor/extractor_config.rb +74 -0
- data/lib/rosette/core/extractor/locale.rb +118 -0
- data/lib/rosette/core/extractor/phrase.rb +76 -0
- data/lib/rosette/core/extractor/phrase/phrase_index_policy.rb +108 -0
- data/lib/rosette/core/extractor/phrase/phrase_to_hash.rb +33 -0
- data/lib/rosette/core/extractor/repo_config.rb +339 -0
- data/lib/rosette/core/extractor/serializer_config.rb +55 -0
- data/lib/rosette/core/extractor/static_extractor.rb +44 -0
- data/lib/rosette/core/extractor/translation.rb +44 -0
- data/lib/rosette/core/extractor/translation/translation_to_hash.rb +28 -0
- data/lib/rosette/core/git/diff_finder.rb +131 -0
- data/lib/rosette/core/git/ref.rb +116 -0
- data/lib/rosette/core/git/repo.rb +378 -0
- data/lib/rosette/core/path_matcher_factory.rb +330 -0
- data/lib/rosette/core/resolvers/extractor_id.rb +37 -0
- data/lib/rosette/core/resolvers/integration_id.rb +37 -0
- data/lib/rosette/core/resolvers/preprocessor_id.rb +38 -0
- data/lib/rosette/core/resolvers/resolver.rb +115 -0
- data/lib/rosette/core/resolvers/serializer_id.rb +37 -0
- data/lib/rosette/core/snapshots/cached_head_snapshot_factory.rb +51 -0
- data/lib/rosette/core/snapshots/cached_snapshot_factory.rb +67 -0
- data/lib/rosette/core/snapshots/head_snapshot_factory.rb +58 -0
- data/lib/rosette/core/snapshots/repo_config_path_filter.rb +83 -0
- data/lib/rosette/core/snapshots/snapshot_factory.rb +184 -0
- data/lib/rosette/core/string_utils.rb +23 -0
- data/lib/rosette/core/translation_status.rb +81 -0
- data/lib/rosette/core/validators.rb +18 -0
- data/lib/rosette/core/validators/commit_validator.rb +62 -0
- data/lib/rosette/core/validators/commits_validator.rb +32 -0
- data/lib/rosette/core/validators/encoding_validator.rb +32 -0
- data/lib/rosette/core/validators/locale_validator.rb +37 -0
- data/lib/rosette/core/validators/repo_validator.rb +33 -0
- data/lib/rosette/core/validators/serializer_validator.rb +37 -0
- data/lib/rosette/core/validators/validator.rb +31 -0
- data/lib/rosette/core/version.rb +8 -0
- data/lib/rosette/data_stores.rb +11 -0
- data/lib/rosette/data_stores/errors.rb +26 -0
- data/lib/rosette/data_stores/phrase_status.rb +59 -0
- data/lib/rosette/integrations.rb +12 -0
- data/lib/rosette/integrations/errors.rb +15 -0
- data/lib/rosette/integrations/integratable.rb +58 -0
- data/lib/rosette/integrations/integration.rb +23 -0
- data/lib/rosette/preprocessors.rb +11 -0
- data/lib/rosette/preprocessors/errors.rb +14 -0
- data/lib/rosette/preprocessors/preprocessor.rb +48 -0
- data/lib/rosette/queuing.rb +14 -0
- data/lib/rosette/queuing/commits.rb +19 -0
- data/lib/rosette/queuing/commits/commit_conductor.rb +90 -0
- data/lib/rosette/queuing/commits/commit_job.rb +93 -0
- data/lib/rosette/queuing/commits/commits_queue_configurator.rb +60 -0
- data/lib/rosette/queuing/commits/extract_stage.rb +46 -0
- data/lib/rosette/queuing/commits/fetch_stage.rb +51 -0
- data/lib/rosette/queuing/commits/finalize_stage.rb +76 -0
- data/lib/rosette/queuing/commits/phrase_storage_granularity.rb +20 -0
- data/lib/rosette/queuing/commits/push_stage.rb +91 -0
- data/lib/rosette/queuing/commits/stage.rb +96 -0
- data/lib/rosette/queuing/job.rb +74 -0
- data/lib/rosette/queuing/queue.rb +28 -0
- data/lib/rosette/queuing/queue_configurator.rb +76 -0
- data/lib/rosette/queuing/worker.rb +30 -0
- data/lib/rosette/serializers.rb +10 -0
- data/lib/rosette/serializers/serializer.rb +98 -0
- data/lib/rosette/tms.rb +9 -0
- data/lib/rosette/tms/repository.rb +95 -0
- data/rosette-core.gemspec +24 -0
- data/spec/core/branch_utils_spec.rb +110 -0
- data/spec/core/commands/git/commit_command_spec.rb +60 -0
- data/spec/core/commands/git/diff_command_spec.rb +263 -0
- data/spec/core/commands/git/fetch_command_spec.rb +61 -0
- data/spec/core/commands/git/repo_snapshot_command_spec.rb +72 -0
- data/spec/core/commands/git/show_command_spec.rb +128 -0
- data/spec/core/commands/git/snapshot_command_spec.rb +86 -0
- data/spec/core/commands/git/status_command_spec.rb +154 -0
- data/spec/core/commands/queuing/enqueue_commit_command_spec.rb +34 -0
- data/spec/core/commands/queuing/requeue_commit_command_spec.rb +46 -0
- data/spec/core/commands/translations/export_command_spec.rb +113 -0
- data/spec/core/commands/translations/translation_lookup_command_spec.rb +58 -0
- data/spec/core/configurator_spec.rb +47 -0
- data/spec/core/error_reporters/buffered_error_reporter_spec.rb +61 -0
- data/spec/core/error_reporters/nil_error_reporter_spec.rb +16 -0
- data/spec/core/error_reporters/printing_error_reporter_spec.rb +60 -0
- data/spec/core/extractor/commit_log_status_spec.rb +216 -0
- data/spec/core/extractor/commit_processor_spec.rb +68 -0
- data/spec/core/extractor/extractor_config_spec.rb +47 -0
- data/spec/core/extractor/extractor_spec.rb +26 -0
- data/spec/core/extractor/locale_spec.rb +92 -0
- data/spec/core/extractor/phrase/phrase_index_policy_spec.rb +116 -0
- data/spec/core/extractor/phrase/phrase_to_hash_spec.rb +18 -0
- data/spec/core/extractor/repo_config_spec.rb +147 -0
- data/spec/core/extractor/translation/translation_to_hash_spec.rb +25 -0
- data/spec/core/git/diff_finder_spec.rb +74 -0
- data/spec/core/git/ref_spec.rb +118 -0
- data/spec/core/git/repo_spec.rb +216 -0
- data/spec/core/path_matcher_factory_spec.rb +139 -0
- data/spec/core/resolvers/extractor_id_spec.rb +47 -0
- data/spec/core/resolvers/integration_id_spec.rb +47 -0
- data/spec/core/resolvers/preprocessor_id_spec.rb +47 -0
- data/spec/core/resolvers/serializer_id_spec.rb +47 -0
- data/spec/core/snapshots/snapshot_factory_spec.rb +145 -0
- data/spec/core/string_utils_spec.rb +19 -0
- data/spec/core/translation_status_spec.rb +91 -0
- data/spec/core/validators/commit_validator_spec.rb +40 -0
- data/spec/core/validators/encoding_validator_spec.rb +30 -0
- data/spec/core/validators/locale_validator_spec.rb +31 -0
- data/spec/core/validators/repo_validator_spec.rb +30 -0
- data/spec/core/validators/serializer_validator_spec.rb +31 -0
- data/spec/integrations/integratable_spec.rb +58 -0
- data/spec/queuing/commits/commit_conductor_spec.rb +71 -0
- data/spec/queuing/commits/commit_job_spec.rb +87 -0
- data/spec/queuing/commits/extract_stage_spec.rb +68 -0
- data/spec/queuing/commits/fetch_stage_spec.rb +101 -0
- data/spec/queuing/commits/finalize_stage_spec.rb +88 -0
- data/spec/queuing/commits/push_stage_spec.rb +145 -0
- data/spec/queuing/commits/stage_spec.rb +80 -0
- data/spec/queuing/job_spec.rb +33 -0
- data/spec/queuing/queue_configurator_spec.rb +44 -0
- data/spec/spec_helper.rb +90 -0
- data/spec/test_helpers/fake_commit_stage.rb +17 -0
- metadata +257 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core::Commands
|
6
|
+
include Rosette::DataStores
|
7
|
+
|
8
|
+
describe RequeueCommitCommand do
|
9
|
+
let(:repo_name) { 'single_commit' }
|
10
|
+
|
11
|
+
let(:fixture) do
|
12
|
+
load_repo_fixture(repo_name) do |config, repo_config|
|
13
|
+
config.use_queue('test')
|
14
|
+
config.use_datastore('in-memory')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:queue) { Rosette::Queuing::TestQueue::Queue }
|
19
|
+
let(:commit_id) { fixture.repo.git('rev-parse HEAD').strip }
|
20
|
+
let(:rosette_config) { fixture.config }
|
21
|
+
let(:command) do
|
22
|
+
RequeueCommitCommand.new(rosette_config)
|
23
|
+
.set_repo_name(repo_name)
|
24
|
+
.set_commit_id(commit_id)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#execute' do
|
28
|
+
let!(:commit_log) do
|
29
|
+
InMemoryDataStore::CommitLog.create(
|
30
|
+
repo_name: repo_name, commit_id: commit_id,
|
31
|
+
status: PhraseStatus::EXTRACTED, phrase_count: 0,
|
32
|
+
branch_name: 'refs/remotes/origin/master',
|
33
|
+
commit_datetime: Time.now
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'enqueues the commit' do
|
38
|
+
expect { command.execute }.to(
|
39
|
+
change { queue.list.size }.from(0).to(1)
|
40
|
+
)
|
41
|
+
|
42
|
+
expect(queue.list.first.commit_id).to eq(commit_id)
|
43
|
+
expect(commit_log.status).to eq(PhraseStatus::NOT_FOUND)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core::Commands
|
6
|
+
|
7
|
+
describe ExportCommand do
|
8
|
+
let(:repo_name) { 'single_commit' }
|
9
|
+
let(:locales) { %w(es de-DE ja-JP) }
|
10
|
+
let(:phrase_model) { Rosette::DataStores::InMemoryDataStore::Phrase }
|
11
|
+
|
12
|
+
let(:fixture) do
|
13
|
+
load_repo_fixture(repo_name) do |config, repo_config|
|
14
|
+
config.use_datastore('in-memory')
|
15
|
+
repo_config.use_tms('test')
|
16
|
+
repo_config.add_locales(locales)
|
17
|
+
repo_config.add_serializer('test', format: 'test/test')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:commit_id) { fixture.repo.git('rev-parse HEAD').strip }
|
22
|
+
let(:rosette_config) { fixture.config }
|
23
|
+
let(:repo_config) { rosette_config.get_repo(repo_name) }
|
24
|
+
let(:command) { ExportCommand.new(rosette_config) }
|
25
|
+
|
26
|
+
before do
|
27
|
+
CommitCommand.new(rosette_config)
|
28
|
+
.set_repo_name(repo_name)
|
29
|
+
.set_ref(commit_id)
|
30
|
+
.execute
|
31
|
+
|
32
|
+
command.set_repo_name(repo_name)
|
33
|
+
.set_ref(commit_id)
|
34
|
+
.set_locale(locales.first)
|
35
|
+
.set_serializer('test/test')
|
36
|
+
|
37
|
+
phrase_model.entries.each do |phrase|
|
38
|
+
repo_config.tms.store_phrase(phrase, commit_id)
|
39
|
+
repo_config.tms.auto_translate(command.send(:locale_obj), phrase)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'exports translations from the given commit' do
|
44
|
+
result = command.execute
|
45
|
+
|
46
|
+
test_pairs = [
|
47
|
+
"I'm a little teapot = i'may aay ittlelay eapottay",
|
48
|
+
"Diamonds are a girl's best friend. = iamondsday areay aay irl'sgay estbay iendfray.",
|
49
|
+
"string2 = esttay ingstray 2"
|
50
|
+
]
|
51
|
+
|
52
|
+
test_pairs.each do |test_pair|
|
53
|
+
expect(result[:payload]).to include(test_pair)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'includes basic information about the payload' do
|
58
|
+
result = command.execute
|
59
|
+
expect(result[:encoding]).to eq('UTF-8')
|
60
|
+
expect(result[:translation_count]).to eq(8)
|
61
|
+
expect(result[:base_64_encoded]).to eq(false)
|
62
|
+
expect(result[:locale]).to eq(locales.first)
|
63
|
+
expect(result[:paths]).to eq([])
|
64
|
+
expect(result).to_not include(:checksum)
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'with base 64 encoding option' do
|
68
|
+
before do
|
69
|
+
command.set_base_64_encode(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'base 64 encodes the payload' do
|
73
|
+
result = command.execute
|
74
|
+
expect(Base64.decode64(result[:payload])).to include(
|
75
|
+
"I'm a little teapot = i'may aay ittlelay eapottay"
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'with checksum option' do
|
81
|
+
before do
|
82
|
+
command.set_include_checksum(true)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'includes a checksum with the payload' do
|
86
|
+
expect(command.execute).to include(:checksum)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'with snapshot option' do
|
91
|
+
before do
|
92
|
+
command.set_include_snapshot(true)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'includes the snapshot' do
|
96
|
+
expect(command.execute[:snapshot]).to eq(
|
97
|
+
'first_file.txt' => commit_id,
|
98
|
+
'folder/second_file.txt' => commit_id,
|
99
|
+
'folder/with_metakeys.txt' => commit_id
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'with a different encoding' do
|
105
|
+
before do
|
106
|
+
command.set_encoding(Encoding::UTF_16)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'includes the encoding alongside the payload' do
|
110
|
+
expect(command.execute[:encoding]).to eq('UTF-16')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core::Commands
|
6
|
+
include Rosette::DataStores
|
7
|
+
include Rosette::Core
|
8
|
+
|
9
|
+
describe TranslationLookupCommand do
|
10
|
+
let(:repo_name) { 'single_commit' }
|
11
|
+
|
12
|
+
let(:fixture) do
|
13
|
+
load_repo_fixture(repo_name) do |config, repo_config|
|
14
|
+
config.use_datastore('in-memory')
|
15
|
+
repo_config.use_tms('test')
|
16
|
+
repo_config.add_locale('de-DE')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:locale) { repo_config.locales.first }
|
21
|
+
let(:commit_id) { fixture.repo.git('rev-parse HEAD').strip }
|
22
|
+
let(:repo_config) { fixture.config.get_repo(repo_name) }
|
23
|
+
let(:rosette_config) { fixture.config }
|
24
|
+
let(:command) do
|
25
|
+
TranslationLookupCommand.new(rosette_config)
|
26
|
+
.set_repo_name(repo_name)
|
27
|
+
.set_locale('de-DE')
|
28
|
+
.set_commit_id(commit_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#execute' do
|
32
|
+
let!(:phrase1) do
|
33
|
+
InMemoryDataStore::Phrase.create(
|
34
|
+
key: 'sweet phrase', meta_key: 'sweet.phrase',
|
35
|
+
repo_name: repo_name, commit_id: commit_id
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
let!(:phrase2) do
|
40
|
+
InMemoryDataStore::Phrase.create(
|
41
|
+
key: 'perfect phrase', meta_key: 'perfect.phrase',
|
42
|
+
repo_name: repo_name, commit_id: commit_id
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'looks up the translation string' do
|
47
|
+
repo_config.tms.store_phrases([phrase1, phrase2], commit_id)
|
48
|
+
repo_config.tms.auto_translate(locale, phrase1)
|
49
|
+
repo_config.tms.auto_translate(locale, phrase2)
|
50
|
+
|
51
|
+
command.set_meta_key(phrase1.meta_key)
|
52
|
+
expect(command.execute).to eq('eetsway asephray')
|
53
|
+
|
54
|
+
command.set_meta_key(phrase2.meta_key)
|
55
|
+
expect(command.execute).to eq('erfectpay asephray')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe Configurator do
|
8
|
+
let(:config) { Configurator.new }
|
9
|
+
|
10
|
+
describe '#add_repo' do
|
11
|
+
it 'yields and adds a repo config' do
|
12
|
+
config.add_repo('foo') do |repo_config|
|
13
|
+
expect(repo_config).to be_a(Rosette::Core::RepoConfig)
|
14
|
+
expect(repo_config.name).to eq('foo')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#get_repo' do
|
20
|
+
it 'returns the repo by name' do
|
21
|
+
config.add_repo('foo') {}
|
22
|
+
config.get_repo('foo').tap do |repo|
|
23
|
+
expect(repo.name).to eq('foo')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#use_datastore' do
|
29
|
+
it 'attempts to look up the datastore constant if passed a string' do
|
30
|
+
config.use_datastore('test')
|
31
|
+
expect(config.datastore).to be_a(Rosette::DataStores::TestDataStore)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'uses the passed in value directly if not passed a string (should be a constant, fyi)' do
|
35
|
+
config.use_datastore(Rosette::DataStores::TestDataStore)
|
36
|
+
expect(config.datastore).to be_a(Rosette::DataStores::TestDataStore)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises an error if the object passed isn't a String or Class" do
|
40
|
+
expect(lambda { config.use_datastore(1) }).to raise_error(ArgumentError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises an error if the datastore couldn't be looked up" do
|
44
|
+
expect(lambda { config.use_datastore('foo') }).to raise_error(ArgumentError)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe BufferedErrorReporter do
|
8
|
+
let(:error) { StandardError.new('jelly beans') }
|
9
|
+
let(:options) { { foo: 'bar' } }
|
10
|
+
let(:reporter) { BufferedErrorReporter.new }
|
11
|
+
|
12
|
+
describe '#report_error' do
|
13
|
+
it 'should log each error' do
|
14
|
+
reporter.report_error(error, options)
|
15
|
+
expect(reporter.errors.size).to eq(1)
|
16
|
+
|
17
|
+
reporter.errors.first.tap do |err|
|
18
|
+
expect(err.keys).to eq([:error, :options])
|
19
|
+
expect(err[:error]).to eq(error)
|
20
|
+
expect(err[:options]).to eq(options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with a reported error' do
|
26
|
+
before(:each) do
|
27
|
+
reporter.report_error(error, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#reset' do
|
31
|
+
it 'should clear the error list' do
|
32
|
+
reporter.reset
|
33
|
+
expect(reporter.errors).to be_empty
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#errors_found?' do
|
38
|
+
it 'returns true if errors have been reported, false otherwise' do
|
39
|
+
expect(reporter.errors_found?).to be_truthy
|
40
|
+
reporter.reset
|
41
|
+
expect(reporter.errors_found?).to be_falsey
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#each_error' do
|
46
|
+
it 'yields each error if given a block' do
|
47
|
+
reporter.each_error do |cur_error, opts|
|
48
|
+
expect(cur_error).to eq(error)
|
49
|
+
expect(opts).to eq(options)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns an enumerator if not given a block' do
|
54
|
+
reporter.each_error.tap do |enum|
|
55
|
+
expect(enum).to be_a(Enumerator)
|
56
|
+
expect(enum.to_a).to include([error, options])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe NilErrorReporter do
|
8
|
+
let(:error) { StandardError.new('jelly beans') }
|
9
|
+
let(:reporter) { NilErrorReporter.instance }
|
10
|
+
|
11
|
+
describe '#report_error' do
|
12
|
+
it 'should respond to the #report_error method' do
|
13
|
+
reporter.report_error(error)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe PrintingErrorReporter do
|
8
|
+
class Collector
|
9
|
+
attr_reader :messages
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@messages = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def write(message)
|
16
|
+
@messages << message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:error) do
|
21
|
+
begin
|
22
|
+
raise StandardError, 'jelly beans'
|
23
|
+
rescue => e
|
24
|
+
e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:collector) { Collector.new }
|
29
|
+
let(:reporter) { PrintingErrorReporter.new(collector) }
|
30
|
+
let(:options) { { foo: 'bar' } }
|
31
|
+
|
32
|
+
describe '#report_error' do
|
33
|
+
it 'prints the error message' do
|
34
|
+
reporter.report_error(error, options)
|
35
|
+
expect(collector.messages.size).to eq(1)
|
36
|
+
expect(collector.messages).to include("jelly beans\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with a reporter that prints a stack trace' do
|
40
|
+
let(:reporter) do
|
41
|
+
PrintingErrorReporter.new(
|
42
|
+
collector, print_stack_trace: true
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'prints a stack trace along with the error message' do
|
47
|
+
reporter.report_error(error, options)
|
48
|
+
expect(collector.messages).to include("jelly beans\n")
|
49
|
+
expect(collector.messages).to include(options.inspect)
|
50
|
+
expect(collector.messages.size).to be > 1
|
51
|
+
|
52
|
+
trace_message = collector.messages.find do |message|
|
53
|
+
message =~ /printing_error_reporter_spec.rb:[\d]+/
|
54
|
+
end
|
55
|
+
|
56
|
+
expect(trace_message).to_not be_nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
include Rosette::DataStores
|
7
|
+
|
8
|
+
class CommitLogStatusTester
|
9
|
+
include CommitLogStatus
|
10
|
+
|
11
|
+
def initialize(initial_status)
|
12
|
+
send('status=', initial_status)
|
13
|
+
end
|
14
|
+
|
15
|
+
def status=(new_status)
|
16
|
+
if new_status
|
17
|
+
@status = new_status
|
18
|
+
|
19
|
+
aasm.set_current_state_with_persistence(
|
20
|
+
new_status.to_sym
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def status
|
26
|
+
aasm.current_state.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe CommitLogStatus do
|
31
|
+
let(:instance) do
|
32
|
+
CommitLogStatusTester.new(status)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with a NOT_SEEN status' do
|
36
|
+
let(:status) { PhraseStatus::NOT_SEEN }
|
37
|
+
|
38
|
+
describe 'on fetch' do
|
39
|
+
it 'transitions to FETCHED' do
|
40
|
+
expect(instance.fetch).to be_truthy
|
41
|
+
expect(instance.status).to eq(PhraseStatus::FETCHED)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'on extract' do
|
46
|
+
it 'raises an error' do
|
47
|
+
expect { instance.extract }.to raise_error(AASM::InvalidTransition)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'on push' do
|
52
|
+
it 'raises an error' do
|
53
|
+
expect { instance.push }.to raise_error(AASM::InvalidTransition)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'on finalize' do
|
58
|
+
it 'raises an error' do
|
59
|
+
expect { instance.finalize }.to raise_error(AASM::InvalidTransition)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'on missing' do
|
64
|
+
it 'transitions to MISSING' do
|
65
|
+
expect(instance.missing).to be_truthy
|
66
|
+
expect(instance.status).to eq(PhraseStatus::MISSING)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with a FETCHED status' do
|
72
|
+
let(:status) { PhraseStatus::FETCHED }
|
73
|
+
|
74
|
+
describe 'on fetch' do
|
75
|
+
it 'raises an error' do
|
76
|
+
expect { instance.fetch }.to raise_error(AASM::InvalidTransition)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'on extract' do
|
81
|
+
it 'transitions to EXTRACTED' do
|
82
|
+
expect(instance.extract).to be_truthy
|
83
|
+
expect(instance.status).to eq(PhraseStatus::EXTRACTED)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'on push' do
|
88
|
+
it 'raises an error' do
|
89
|
+
expect { instance.push }.to raise_error(AASM::InvalidTransition)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'on finalize' do
|
94
|
+
it 'raises an error' do
|
95
|
+
expect { instance.finalize }.to raise_error(AASM::InvalidTransition)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'on missing' do
|
100
|
+
it 'transitions to MISSING' do
|
101
|
+
expect(instance.missing).to be_truthy
|
102
|
+
expect(instance.status).to eq(PhraseStatus::MISSING)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with an EXTRACTED status' do
|
108
|
+
let(:status) { PhraseStatus::EXTRACTED }
|
109
|
+
|
110
|
+
describe 'on fetch' do
|
111
|
+
it 'raises an error' do
|
112
|
+
expect { instance.fetch }.to raise_error(AASM::InvalidTransition)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'on extract' do
|
117
|
+
it 'raises an error' do
|
118
|
+
expect { instance.extract }.to raise_error(AASM::InvalidTransition)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'on push' do
|
123
|
+
it 'transitions to PUSHED' do
|
124
|
+
expect(instance.push).to be_truthy
|
125
|
+
expect(instance.status).to eq(PhraseStatus::PUSHED)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'on finalize' do
|
130
|
+
it 'transitions to FINALIZED' do
|
131
|
+
expect(instance.finalize).to be_truthy
|
132
|
+
expect(instance.status).to eq(PhraseStatus::FINALIZED)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'on missing' do
|
137
|
+
it 'transitions to MISSING' do
|
138
|
+
expect(instance.missing).to be_truthy
|
139
|
+
expect(instance.status).to eq(PhraseStatus::MISSING)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'with a PUSHED status' do
|
145
|
+
let(:status) { PhraseStatus::PUSHED }
|
146
|
+
|
147
|
+
describe 'on fetch' do
|
148
|
+
it 'raises an error' do
|
149
|
+
expect { instance.fetch }.to raise_error(AASM::InvalidTransition)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe 'on extract' do
|
154
|
+
it 'raises an error' do
|
155
|
+
expect { instance.extract }.to raise_error(AASM::InvalidTransition)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'on push' do
|
160
|
+
it 'stays PUSHED' do
|
161
|
+
expect(instance.push).to be_truthy
|
162
|
+
expect(instance.status).to eq(PhraseStatus::PUSHED)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'on finalize' do
|
167
|
+
it 'transitions to FINALIZED' do
|
168
|
+
expect(instance.finalize).to be_truthy
|
169
|
+
expect(instance.status).to eq(PhraseStatus::FINALIZED)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'on missing' do
|
174
|
+
it 'transitions to MISSING' do
|
175
|
+
expect(instance.missing).to be_truthy
|
176
|
+
expect(instance.status).to eq(PhraseStatus::MISSING)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'with a FINALIZED status' do
|
182
|
+
let(:status) { PhraseStatus::FINALIZED }
|
183
|
+
|
184
|
+
describe 'on fetch' do
|
185
|
+
it 'raises an error' do
|
186
|
+
expect { instance.fetch }.to raise_error(AASM::InvalidTransition)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'on extract' do
|
191
|
+
it 'raises an error' do
|
192
|
+
expect { instance.extract }.to raise_error(AASM::InvalidTransition)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe 'on push' do
|
197
|
+
it 'raises an error' do
|
198
|
+
expect { instance.push }.to raise_error(AASM::InvalidTransition)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe 'on finalize' do
|
203
|
+
it 'stays FINALIZED' do
|
204
|
+
expect(instance.finalize).to be_truthy
|
205
|
+
expect(instance.status).to eq(PhraseStatus::FINALIZED)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe 'on missing' do
|
210
|
+
it 'transitions to MISSING' do
|
211
|
+
expect(instance.missing).to be_truthy
|
212
|
+
expect(instance.status).to eq(PhraseStatus::MISSING)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|