nabokov 0.1.0

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 (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.gitignore +43 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +113 -0
  6. data/.travis.yml +14 -0
  7. data/CHANGELOG.md +5 -0
  8. data/Gemfile +9 -0
  9. data/LICENSE +21 -0
  10. data/README.md +16 -0
  11. data/Rakefile +22 -0
  12. data/bin/nabokov +5 -0
  13. data/lib/nabokov/commands/runner.rb +22 -0
  14. data/lib/nabokov/commands/setup.rb +75 -0
  15. data/lib/nabokov/commands/syncers/localizations_repo_syncer.rb +101 -0
  16. data/lib/nabokov/commands/syncers/project_syncer.rb +106 -0
  17. data/lib/nabokov/commands/syncers/syncer.rb +68 -0
  18. data/lib/nabokov/core/file_manager.rb +36 -0
  19. data/lib/nabokov/core/nabokovfile.rb +66 -0
  20. data/lib/nabokov/core/nabokovfile_content_validator.rb +51 -0
  21. data/lib/nabokov/core/nabokovfile_keys.rb +34 -0
  22. data/lib/nabokov/git/git_repo.rb +137 -0
  23. data/lib/nabokov/helpers/informator.rb +83 -0
  24. data/lib/nabokov/helpers/merger.rb +86 -0
  25. data/lib/nabokov/models/strings_file.rb +7 -0
  26. data/lib/nabokov/version.rb +8 -0
  27. data/lib/nabokov.rb +14 -0
  28. data/nabokov.gemspec +31 -0
  29. data/spec/fixtures/.DS_Store +0 -0
  30. data/spec/fixtures/README.md +1 -0
  31. data/spec/fixtures/de.strings +1 -0
  32. data/spec/fixtures/en.strings +1 -0
  33. data/spec/fixtures/nabokovfile_example.yaml +9 -0
  34. data/spec/fixtures/nabokovfile_example_invalid.yaml +2 -0
  35. data/spec/fixtures/nabokovfile_example_without_master_branch.yaml +8 -0
  36. data/spec/fixtures/test_git_setup/existed_pre_commit_file +0 -0
  37. data/spec/fixtures/test_git_setup/existed_pre_commit_file_alias +0 -0
  38. data/spec/fixtures/test_git_setup/not_executable_pre_commit_file +0 -0
  39. data/spec/fixtures/test_localizations_repo_syncer/localizations_repo_fixtures/README.md +1 -0
  40. data/spec/fixtures/test_localizations_repo_syncer/nabokovfile.yaml +8 -0
  41. data/spec/fixtures/test_project_syncer/localizations_repo_fixtures/de.strings +2 -0
  42. data/spec/fixtures/test_project_syncer/localizations_repo_fixtures/en.strings +2 -0
  43. data/spec/fixtures/test_project_syncer/project_repo_fixtures/de.strings +2 -0
  44. data/spec/fixtures/test_project_syncer/project_repo_fixtures/en.strings +2 -0
  45. data/spec/fixtures/test_project_syncer/project_repo_fixtures/nabokovfile.yaml +9 -0
  46. data/spec/lib/nabokov/commands/localizations_repo_syncer_spec.rb +137 -0
  47. data/spec/lib/nabokov/commands/project_syncer_spec.rb +61 -0
  48. data/spec/lib/nabokov/commands/runner_spec.rb +7 -0
  49. data/spec/lib/nabokov/commands/setup_spec.rb +101 -0
  50. data/spec/lib/nabokov/commands/syncer_spec.rb +23 -0
  51. data/spec/lib/nabokov/core/file_manager_spec.rb +115 -0
  52. data/spec/lib/nabokov/core/nabokovfile_content_validator_spec.rb +155 -0
  53. data/spec/lib/nabokov/core/nabokovfile_keyes_spec.rb +31 -0
  54. data/spec/lib/nabokov/core/nabokovfile_spec.rb +53 -0
  55. data/spec/lib/nabokov/git/git_repo_spec.rb +670 -0
  56. data/spec/lib/nabokov/helpers/informator_spec.rb +49 -0
  57. data/spec/lib/nabokov/helpers/merger_spec.rb +114 -0
  58. data/spec/lib/nabokov/models/strings_file_spec.rb +7 -0
  59. data/spec/spec_helper.rb +11 -0
  60. metadata +238 -0
@@ -0,0 +1,137 @@
1
+ require "nabokov/commands/syncers/localizations_repo_syncer"
2
+ require "nabokov/git/git_repo"
3
+ require "nabokov/helpers/merger"
4
+ require "nabokov/helpers/informator"
5
+
6
+ describe Nabokov::LocalizationsRepoSyncer do
7
+ before(:each) do
8
+ allow(STDOUT).to receive(:puts)
9
+ end
10
+
11
+ it "is not an abstract command" do
12
+ expect(Nabokov::LocalizationsRepoSyncer.abstract_command).to be_falsy
13
+ end
14
+
15
+ describe "run" do
16
+ context "when the repo is empty" do
17
+ before(:all) do
18
+ @test_git_repo_path = File.expand_path("spec/fixtures/test_localizations_repo_syncer/localizations_repo")
19
+ @test_git_repo_url = "https://github.com/Antondomashnev/nabokov_example.git"
20
+ end
21
+
22
+ before(:each) do
23
+ prepare_repo(@test_git_repo_path, "spec/fixtures/test_localizations_repo_syncer/localizations_repo_fixtures/.")
24
+
25
+ @mock_nabokovfile = Nabokov::Nabokovfile.new("spec/fixtures/test_localizations_repo_syncer/nabokovfile.yaml")
26
+ allow(@mock_nabokovfile).to receive(:localizations_repo_local_path).and_return(@test_git_repo_path)
27
+
28
+ @mock_git_repo = Nabokov::GitRepo.new(@test_git_repo_path, @test_git_repo_url, object_double(Git::Base))
29
+ allow(@mock_git_repo).to receive(:log).with(1).and_return("1234567890")
30
+
31
+ @merger = Nabokov::Merger.new(object_double(Nabokov::Informator), object_double(Nabokov::GitRepo))
32
+
33
+ allow(Nabokov::Nabokovfile).to receive(:new).with(anything).and_return(@mock_nabokovfile)
34
+ allow(Nabokov::GitRepo).to receive(:new).with(anything, anything).and_return(@mock_git_repo)
35
+ allow(Nabokov::Merger).to receive(:new).with(anything, anything, anything).and_return(@merger)
36
+
37
+ allow_any_instance_of(Nabokov::Informator).to receive(:wait_for_return)
38
+ end
39
+
40
+ after(:each) do
41
+ FileUtils.rm_rf(Dir.glob("spec/fixtures/test_localizations_repo_syncer/localizations_repo"))
42
+ end
43
+
44
+ context "when files don't have any changes to sync" do
45
+ before do
46
+ allow(@mock_git_repo).to receive(:changes?).and_return(false)
47
+ end
48
+
49
+ it "runs the commands in the correct order" do
50
+ expect(@mock_git_repo).to receive(:init).ordered
51
+ expect(@mock_git_repo).to receive(:checkout_branch).with("master").ordered
52
+ expect(@mock_git_repo).to receive(:checkout_branch).with("nabokov/temporary_branch").ordered
53
+ expect(@mock_git_repo).to receive(:add).with("#{@test_git_repo_path}/en.strings").ordered
54
+ expect(@mock_git_repo).to receive(:add).with("#{@test_git_repo_path}/de.strings").ordered
55
+ expect(@mock_git_repo).to receive(:checkout_branch).with("master").ordered
56
+ expect(@mock_git_repo).to receive(:pull).ordered
57
+ expect(@mock_git_repo).to receive(:delete_branch).with("nabokov/temporary_branch").ordered
58
+
59
+ Nabokov::LocalizationsRepoSyncer.run(["--nabokovfile=spec/fixtures/nabokovfile_example_without_master_branch.yaml"])
60
+ end
61
+ end
62
+
63
+ context "when files have changes to sync" do
64
+ before do
65
+ allow(@mock_git_repo).to receive(:changes?).and_return(true)
66
+ end
67
+
68
+ context "when merge doesn't have conflicts" do
69
+ before do
70
+ allow(@merger).to receive(:merge).with("master", "nabokov/temporary_branch").and_return(Nabokov::MergerResult::SUCCEEDED)
71
+ end
72
+
73
+ it "runs the commands in the correct order" do
74
+ expect(@mock_git_repo).to receive(:init).ordered
75
+ expect(@mock_git_repo).to receive(:checkout_branch).with("master").ordered
76
+ expect(@mock_git_repo).to receive(:checkout_branch).with("nabokov/temporary_branch").ordered
77
+ expect(@mock_git_repo).to receive(:add).with("#{@test_git_repo_path}/en.strings").ordered
78
+ expect(@mock_git_repo).to receive(:commit).with("Nabokov localization file 'en' update...").ordered
79
+ expect(@mock_git_repo).to receive(:add).with("#{@test_git_repo_path}/de.strings").ordered
80
+ expect(@mock_git_repo).to receive(:commit).with("Nabokov localization file 'de' update...").ordered
81
+ expect(@mock_git_repo).to receive(:checkout_branch).with("master").ordered
82
+ expect(@mock_git_repo).to receive(:pull).ordered
83
+ expect(@mock_git_repo).to receive(:push).ordered
84
+ expect(@mock_git_repo).to receive(:delete_branch).with("nabokov/temporary_branch").ordered
85
+
86
+ Nabokov::LocalizationsRepoSyncer.run(["--nabokovfile=spec/fixtures/nabokovfile_example_without_master_branch.yaml"])
87
+ end
88
+ end
89
+
90
+ context "when merge has conflicts" do
91
+ context "when merge is aborted" do
92
+ before do
93
+ allow(@merger).to receive(:merge).with("master", "nabokov/temporary_branch").and_return(Nabokov::MergerResult::ABORTED)
94
+ end
95
+
96
+ it "runs the commands in the correct order" do
97
+ expect(@mock_git_repo).to receive(:init).ordered
98
+ expect(@mock_git_repo).to receive(:checkout_branch).with("master").ordered
99
+ expect(@mock_git_repo).to receive(:checkout_branch).with("nabokov/temporary_branch").ordered
100
+ expect(@mock_git_repo).to receive(:add).with("#{@test_git_repo_path}/en.strings").ordered
101
+ expect(@mock_git_repo).to receive(:commit).with("Nabokov localization file 'en' update...").ordered
102
+ expect(@mock_git_repo).to receive(:add).with("#{@test_git_repo_path}/de.strings").ordered
103
+ expect(@mock_git_repo).to receive(:commit).with("Nabokov localization file 'de' update...").ordered
104
+ expect(@mock_git_repo).to receive(:checkout_branch).with("master").ordered
105
+ expect(@mock_git_repo).to receive(:pull).ordered
106
+ expect(@mock_git_repo).to receive(:delete_branch).with("nabokov/temporary_branch").ordered
107
+
108
+ Nabokov::LocalizationsRepoSyncer.run(["--nabokovfile=spec/fixtures/nabokovfile_example_without_master_branch.yaml"])
109
+ end
110
+ end
111
+
112
+ context "when merge is succeeded" do
113
+ before do
114
+ allow(@merger).to receive(:merge).with("master", "nabokov/temporary_branch").and_return(Nabokov::MergerResult::SUCCEEDED)
115
+ end
116
+
117
+ it "runs the commands in the correct order" do
118
+ expect(@mock_git_repo).to receive(:init).ordered
119
+ expect(@mock_git_repo).to receive(:checkout_branch).with("master").ordered
120
+ expect(@mock_git_repo).to receive(:checkout_branch).with("nabokov/temporary_branch").ordered
121
+ expect(@mock_git_repo).to receive(:add).with("#{@test_git_repo_path}/en.strings").ordered
122
+ expect(@mock_git_repo).to receive(:commit).with("Nabokov localization file 'en' update...").ordered
123
+ expect(@mock_git_repo).to receive(:add).with("#{@test_git_repo_path}/de.strings").ordered
124
+ expect(@mock_git_repo).to receive(:commit).with("Nabokov localization file 'de' update...").ordered
125
+ expect(@mock_git_repo).to receive(:checkout_branch).with("master").ordered
126
+ expect(@mock_git_repo).to receive(:pull).ordered
127
+ expect(@mock_git_repo).to receive(:push).ordered
128
+ expect(@mock_git_repo).to receive(:delete_branch).with("nabokov/temporary_branch").ordered
129
+
130
+ Nabokov::LocalizationsRepoSyncer.run(["--nabokovfile=spec/fixtures/nabokovfile_example_without_master_branch.yaml"])
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,61 @@
1
+ require "nabokov/commands/syncers/project_syncer"
2
+ require "fileutils"
3
+
4
+ describe Nabokov::ProjectSyncer do
5
+ before(:each) do
6
+ allow(STDOUT).to receive(:puts)
7
+ end
8
+
9
+ it "is not an abstract command" do
10
+ expect(Nabokov::ProjectSyncer.abstract_command).to be_falsy
11
+ end
12
+
13
+ describe "run" do
14
+ context "when localiztions repo containes all localization files from the project repo" do
15
+ before(:all) do
16
+ @test_localizations_repo_path = "spec/fixtures/test_project_syncer/localizations_repo"
17
+ @test_project_repo_path = "spec/fixtures/test_project_syncer/project_repo"
18
+ end
19
+
20
+ before(:each) do
21
+ prepare_repo(@test_localizations_repo_path, "spec/fixtures/test_project_syncer/localizations_repo_fixtures/.")
22
+ prepare_repo(@test_project_repo_path, "spec/fixtures/test_project_syncer/project_repo_fixtures/.")
23
+
24
+ @mock_nabokovfile = Nabokov::Nabokovfile.new("spec/fixtures/test_project_syncer/project_repo/nabokovfile.yaml")
25
+ allow(@mock_nabokovfile).to receive(:localizations_repo_local_path).and_return(@test_localizations_repo_path)
26
+
27
+ @mock_localizations_repo = Nabokov::GitRepo.new(@mock_nabokovfile.localizations_repo_local_path, @mock_nabokovfile.localizations_repo_url)
28
+ allow(@mock_localizations_repo).to receive(:pull)
29
+
30
+ @mock_project_repo = Nabokov::GitRepo.new(@mock_nabokovfile.project_local_path)
31
+
32
+ allow(Nabokov::Nabokovfile).to receive(:new).with("spec/fixtures/test_project_syncer/project_repo/nabokovfile.yaml").and_return(@mock_nabokovfile)
33
+ allow(Nabokov::GitRepo).to receive(:new).with(@mock_nabokovfile.localizations_repo_local_path, @mock_nabokovfile.localizations_repo_url).and_return(@mock_localizations_repo)
34
+ allow(Nabokov::GitRepo).to receive(:new).with(@mock_nabokovfile.project_local_path).and_return(@mock_project_repo)
35
+ end
36
+
37
+ after do
38
+ FileUtils.rm_rf(Dir.glob(@test_localizations_repo_path))
39
+ FileUtils.rm_rf(Dir.glob(@test_project_repo_path))
40
+ end
41
+
42
+ it "should merge remote localizations with project's localization" do
43
+ Nabokov::ProjectSyncer.run(["--nabokovfile=spec/fixtures/test_project_syncer/project_repo/nabokovfile.yaml"])
44
+
45
+ expected_en_localization_strings = ["\"hello\" = \"Hello\";\n", "\"bye\" = \"Bye\";\n"]
46
+ actual_en_localization_strings = []
47
+ File.readlines("#{@test_project_repo_path}/en.strings").each do |line|
48
+ actual_en_localization_strings << line
49
+ end
50
+ expect(actual_en_localization_strings).to eql(expected_en_localization_strings)
51
+
52
+ expected_de_localization_strings = ["\"hello\" = \"Hallo\";\n", "\"bye\" = \"Tschuss\";\n"]
53
+ actual_de_localization_strings = []
54
+ File.readlines("#{@test_project_repo_path}/de.strings").each do |line|
55
+ actual_de_localization_strings << line
56
+ end
57
+ expect(actual_de_localization_strings).to eql(expected_de_localization_strings)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ require "nabokov/commands/runner"
2
+
3
+ describe Nabokov::Runner do
4
+ it "has the correct version" do
5
+ expect(Nabokov::Runner.version).to eq(Nabokov::VERSION)
6
+ end
7
+ end
@@ -0,0 +1,101 @@
1
+ require "nabokov/commands/setup"
2
+ require "fileutils"
3
+ require "git"
4
+
5
+ describe Nabokov::Setup do
6
+ describe "run" do
7
+ before(:all) do
8
+ FileUtils.mkdir_p("spec/fixtures/test_git_setup/git_folder")
9
+ Git.init("spec/fixtures/test_git_setup/git_folder")
10
+ end
11
+
12
+ after(:all) do
13
+ FileUtils.rm_rf("spec/fixtures/test_git_setup/git_folder")
14
+ end
15
+
16
+ before(:each) do
17
+ allow(STDOUT).to receive(:puts)
18
+ end
19
+
20
+ context "when pre_commit_file path is a file" do
21
+ it "uses the given path" do
22
+ setup = Nabokov::Setup.run(["--pre_commit_file=spec/fixtures/test_git_setup/existed_pre_commit_file", "--git_path=spec/fixtures/test_git_setup"])
23
+ expect(setup.pre_commit_file).to eql("spec/fixtures/test_git_setup/existed_pre_commit_file")
24
+ end
25
+ end
26
+
27
+ context "when pre_commit_file path is a symlink" do
28
+ it "uses the real path" do
29
+ setup = Nabokov::Setup.run(["--pre_commit_file=spec/fixtures/test_git_setup/existed_pre_commit_file_alias", "--git_path=spec/fixtures/test_git_setup"])
30
+ expect(setup.pre_commit_file).to end_with("spec/fixtures/test_git_setup/existed_pre_commit_file")
31
+ end
32
+ end
33
+
34
+ context "when pre_commit_file doesn't exist" do
35
+ context "when the given git_path there is no folder" do
36
+ it "raises an exception" do
37
+ expect { Nabokov::Setup.run(["--pre_commit_file=spec/fixtures/test_git_setup/missing_file", "--git_path=spec/fixtures/test_git_setup_fake"]) }.to raise_error(".git folder is not found at 'spec/fixtures/test_git_setup_fake'")
38
+ end
39
+ end
40
+
41
+ it "creates a pre_commit_file at the given git_path/hooks/pre_commit" do
42
+ setup = Nabokov::Setup.run(["--pre_commit_file=spec/fixtures/test_git_setup/missing_file", "--git_path=spec/fixtures/test_git_setup/git_folder/.git"])
43
+ expect(File.exist?(setup.pre_commit_file)).to be_truthy
44
+ FileUtils.rm_rf(Dir.glob("spec/fixtures/test_git_setup/git_folder/.git/*"))
45
+ end
46
+ end
47
+
48
+ context "when pre_commit_file is not executable" do
49
+ it "raises an exception" do
50
+ input = ["--pre_commit_file=spec/fixtures/test_git_setup/not_executable_pre_commit_file", "--git_path=spec/fixtures/test_git_setup/git_folder/.git"]
51
+ expect { Nabokov::Setup.run(input) }.to raise_error("pre commit file at 'spec/fixtures/test_git_setup/not_executable_pre_commit_file' is not executable by the effective user id of this process")
52
+ end
53
+ end
54
+
55
+ context "when current git repo is not listed in pre_commit_file" do
56
+ before(:each) do
57
+ input = ["--pre_commit_file=spec/fixtures/test_git_setup/existed_pre_commit_file", "--git_path=spec/fixtures/test_git_setup/git_folder/.git"]
58
+ Nabokov::Setup.run(input)
59
+ end
60
+
61
+ after(:each) do
62
+ File.truncate("spec/fixtures/test_git_setup/existed_pre_commit_file", 0)
63
+ end
64
+
65
+ it "puts into pre commit line to tell that file is executable" do
66
+ result = File.foreach("spec/fixtures/test_git_setup/existed_pre_commit_file").any? do |line|
67
+ line.include?("#!\/usr\/bin\/env bash")
68
+ end
69
+ expect(result).to be_truthy
70
+ end
71
+
72
+ it "puts into pre commit line about current repo path" do
73
+ result = File.foreach("spec/fixtures/test_git_setup/existed_pre_commit_file").any? do |line|
74
+ line.include?("current_repo_path=\$(git rev-parse --show-toplevel)")
75
+ end
76
+ expect(result).to be_truthy
77
+ end
78
+
79
+ it "puts into pre commit line about nabokovfile path" do
80
+ result = File.foreach("spec/fixtures/test_git_setup/existed_pre_commit_file").any? do |line|
81
+ line.include?("nabokovfile_path=\"$current_repo_path\/Nabokovfile.yaml\"")
82
+ end
83
+ expect(result).to be_truthy
84
+ end
85
+
86
+ it "puts into pre commit line about tracking repo path" do
87
+ result = File.foreach("spec/fixtures/test_git_setup/existed_pre_commit_file").any? do |line|
88
+ line.include?("tracking_repo_path=")
89
+ end
90
+ expect(result).to be_truthy
91
+ end
92
+
93
+ it "puts into pre commit line to exectute nabokov" do
94
+ result = File.foreach("spec/fixtures/test_git_setup/existed_pre_commit_file").any? do |line|
95
+ line.include?("if [ \"$current_repo_path\" == \"$tracking_repo_path\" ] && gem list -i nabokov && [ -e \"$nabokovfile_path\" ]; then nabokov sync localizations --nabokovfile=$nabokovfile_path || exit 1; fi")
96
+ end
97
+ expect(result).to be_truthy
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,23 @@
1
+ require "nabokov/commands/syncers/syncer"
2
+
3
+ describe Nabokov::Syncer do
4
+ before(:each) do
5
+ allow(STDOUT).to receive(:puts)
6
+ end
7
+
8
+ it "is an abstract command" do
9
+ expect(Nabokov::Syncer.abstract_command).to be_truthy
10
+ end
11
+
12
+ context "when --nabokovfile parameter is not passed" do
13
+ it "raises an error" do
14
+ expect { Nabokov::Syncer.run([]) }.to raise_error("--nabokovfile is a required parameter and could not be nil")
15
+ end
16
+ end
17
+
18
+ context "when nabokovfile doesn't exist at the given path" do
19
+ it "raises a runtime error" do
20
+ expect { Nabokov::Syncer.run(["--nabokovfile=spec/blabla"]) }.to raise_error(SystemExit)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,115 @@
1
+ require "nabokov/core/file_manager"
2
+
3
+ describe Nabokov::FileManager do
4
+ describe "copy and rename" do
5
+ before do
6
+ @test_copy_folder_path = "spec/fixtures/test_copy_folder/"
7
+ FileUtils.mkdir_p("spec/fixtures/test_copy_folder")
8
+ end
9
+
10
+ after do
11
+ FileUtils.rm_rf("spec/fixtures/test_copy_folder")
12
+ end
13
+
14
+ context "when there is no file at from_path" do
15
+ it "raises an exception" do
16
+ from_path = "spec/fixtures/fr.strings"
17
+ new_file_name = "fr.strings"
18
+ expect { Nabokov::FileManager.copy_and_rename(from_path, @test_copy_folder_path, new_file_name) }.to raise_error("Couldn't find file at 'spec/fixtures/fr.strings'")
19
+ end
20
+ end
21
+
22
+ context "when there is no directory to copy to" do
23
+ it "raises an exception" do
24
+ from_path = "spec/fixtures/de.strings"
25
+ new_file_name = "fr.strings"
26
+ expect { Nabokov::FileManager.copy_and_rename(from_path, "spec/fixtures/test_copy_folder_fake", new_file_name) }.to raise_error("Couldn't find directory at 'spec/fixtures/test_copy_folder_fake'")
27
+ end
28
+ end
29
+
30
+ context "when the new file name is empty" do
31
+ it "raises an exception" do
32
+ from_path = "spec/fixtures/de.strings"
33
+ new_file_name = ""
34
+ expect { Nabokov::FileManager.copy_and_rename(from_path, @test_copy_folder_path, new_file_name) }.to raise_error("New name of the file could not be empty")
35
+ end
36
+ end
37
+
38
+ context "when the new file name contains the '.'" do
39
+ it "raises an exception because it messes up with the extension delimeter" do
40
+ from_path = "spec/fixtures/de.strings"
41
+ new_file_name = "fr.de"
42
+ expect { Nabokov::FileManager.copy_and_rename(from_path, @test_copy_folder_path, new_file_name) }.to raise_error("New name of the file 'fr.de' contains invalid character '.'")
43
+ end
44
+ end
45
+
46
+ context "when all requirenments are fulfilled" do
47
+ it "copies the file according input parameters" do
48
+ from_path = "spec/fixtures/de.strings"
49
+ new_file_name = "fr"
50
+ new_file_path = Nabokov::FileManager.copy_and_rename(from_path, @test_copy_folder_path, new_file_name)
51
+ expect(File.file?(new_file_path)).to be_truthy
52
+ end
53
+
54
+ it "overwrites the file according input parameters" do
55
+ from_path = "spec/fixtures/de.strings"
56
+ new_file_name = "fr"
57
+ Nabokov::FileManager.copy_and_rename(from_path, @test_copy_folder_path, new_file_name)
58
+ time_before_copy = File.mtime("spec/fixtures/test_copy_folder/fr.strings")
59
+ new_file_path = Nabokov::FileManager.copy_and_rename(from_path, @test_copy_folder_path, new_file_name)
60
+ expect(File.mtime(new_file_path)).to be >= time_before_copy
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "remove" do
66
+ context "when the given path is neither directory nor file" do
67
+ it "raises an error" do
68
+ expect { Nabokov::FileManager.remove("spec/fixtures/not_existed_file.rb") }.to raise_error("Can not file neither file nor directory at 'spec/fixtures/not_existed_file.rb'")
69
+ end
70
+ end
71
+
72
+ context "when the given path is file" do
73
+ before do
74
+ @file_path = "spec/fixtures/test_copy_folder/file.rb"
75
+ FileUtils.mkdir_p(@file_path)
76
+ end
77
+
78
+ it "removes the file at the given path" do
79
+ Nabokov::FileManager.remove(@file_path)
80
+ expect(File.exist?(@file_path)).to be_falsy
81
+ end
82
+ end
83
+
84
+ context "when the given path is directory" do
85
+ before do
86
+ @folder_path = "spec/fixtures/test_copy_folder/folder"
87
+ FileUtils.mkdir_p(@folder_path)
88
+ end
89
+
90
+ it "removes the directory at the given path" do
91
+ Nabokov::FileManager.remove(@folder_path)
92
+ expect(Dir.exist?(@folder_path)).to be_falsy
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "copy" do
98
+ context "when file to copy doesn't exist at the given path" do
99
+ it "raises an error" do
100
+ expect { Nabokov::FileManager.copy("dsaklgadsg/fadsgf/rewr.rb", "spec/fixtures/test_copy_folder/file.rb") }.to raise_error("Couldn't find file at 'dsaklgadsg/fadsgf/rewr.rb'")
101
+ end
102
+ end
103
+
104
+ context "when file exists at the given path" do
105
+ after do
106
+ FileUtils.rm_rf(Dir.glob("spec/fixtures/test_copy_folder/*"))
107
+ end
108
+
109
+ it "copies file to the given path" do
110
+ Nabokov::FileManager.copy("spec/fixtures/de.strings", "spec/fixtures/test_copy_folder/file.rb")
111
+ expect(File.exist?("spec/fixtures/test_copy_folder/file.rb"))
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,155 @@
1
+ require "nabokov/core/nabokovfile_content_validator"
2
+ require "nabokov/core/nabokovfile_keys"
3
+
4
+ describe Nabokov::NabokovfileContentValidator do
5
+ before do
6
+ @valid_hash = {
7
+ Nabokov::NabokovfileKeyes.localizations_repo => { Nabokov::NabokovfileKeyes.localizations_repo_url => "https://github.com/nabokov/nabokov", Nabokov::NabokovfileKeyes.localizations_repo_master_branch => "nabokov_master" },
8
+ Nabokov::NabokovfileKeyes.project_repo => { Nabokov::NabokovfileKeyes.project_localization_file_paths => { "en" => "spec/fixtures/en.strings", "de" => "spec/fixtures/de.strings" }, Nabokov::NabokovfileKeyes.project_local_path => "spec/fixtures/local_project" }
9
+ }
10
+ end
11
+
12
+ context "when the git repo URL is not in valid URL format" do
13
+ it "raises an error" do
14
+ @valid_hash[Nabokov::NabokovfileKeyes.localizations_repo][Nabokov::NabokovfileKeyes.localizations_repo_url] = "bla_bla_bla"
15
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
16
+ expect { validator.validate }.to raise_error("'bla_bla_bla' is not a valid URL")
17
+ end
18
+ end
19
+
20
+ context "when the git repo URL valid but scheme is not https" do
21
+ it "raises an exception" do
22
+ @valid_hash[Nabokov::NabokovfileKeyes.localizations_repo][Nabokov::NabokovfileKeyes.localizations_repo_url] = "http://github.com/nabokov/nabokov"
23
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
24
+ expect { validator.validate }.to raise_error("Please use 'https://...' instead of 'http://github.com/nabokov/nabokov' only supports encrypted requests")
25
+ end
26
+ end
27
+
28
+ context "when the localizations_repo is not a type of Hash" do
29
+ context "when string" do
30
+ it "raises an error" do
31
+ @valid_hash[Nabokov::NabokovfileKeyes.localizations_repo] = "param:pam"
32
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
33
+ expect { validator.validate }.to raise_error("Localizations repo must be a type of Hash")
34
+ end
35
+ end
36
+
37
+ context "when array" do
38
+ it "raises an error" do
39
+ @valid_hash[Nabokov::NabokovfileKeyes.localizations_repo] = ["key", "value"]
40
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
41
+ expect { validator.validate }.to raise_error("Localizations repo must be a type of Hash")
42
+ end
43
+ end
44
+
45
+ context "when number" do
46
+ it "raises an error" do
47
+ @valid_hash[Nabokov::NabokovfileKeyes.localizations_repo] = 10
48
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
49
+ expect { validator.validate }.to raise_error("Localizations repo must be a type of Hash")
50
+ end
51
+ end
52
+ end
53
+
54
+ context "when the project_repo is not a type of Hash" do
55
+ context "when string" do
56
+ it "raises an error" do
57
+ @valid_hash[Nabokov::NabokovfileKeyes.project_repo] = "param:pam"
58
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
59
+ expect { validator.validate }.to raise_error("Project repo must be a type of Hash")
60
+ end
61
+ end
62
+
63
+ context "when array" do
64
+ it "raises an error" do
65
+ @valid_hash[Nabokov::NabokovfileKeyes.project_repo] = ["key", "value"]
66
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
67
+ expect { validator.validate }.to raise_error("Project repo must be a type of Hash")
68
+ end
69
+ end
70
+
71
+ context "when number" do
72
+ it "raises an error" do
73
+ @valid_hash[Nabokov::NabokovfileKeyes.project_repo] = 10
74
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
75
+ expect { validator.validate }.to raise_error("Project repo must be a type of Hash")
76
+ end
77
+ end
78
+ end
79
+
80
+ context "when the localizations_repo is not a type of Hash" do
81
+ context "when string" do
82
+ it "raises an error" do
83
+ @valid_hash[Nabokov::NabokovfileKeyes.localizations_repo] = "param:pam"
84
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
85
+ expect { validator.validate }.to raise_error("Localizations repo must be a type of Hash")
86
+ end
87
+ end
88
+
89
+ context "when array" do
90
+ it "raises an error" do
91
+ @valid_hash[Nabokov::NabokovfileKeyes.localizations_repo] = ["key", "value"]
92
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
93
+ expect { validator.validate }.to raise_error("Localizations repo must be a type of Hash")
94
+ end
95
+ end
96
+
97
+ context "when number" do
98
+ it "raises an error" do
99
+ @valid_hash[Nabokov::NabokovfileKeyes.localizations_repo] = 10
100
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
101
+ expect { validator.validate }.to raise_error("Localizations repo must be a type of Hash")
102
+ end
103
+ end
104
+ end
105
+
106
+ context "when there is no project repo local path" do
107
+ it "raises an error" do
108
+ @valid_hash[Nabokov::NabokovfileKeyes.project_repo][Nabokov::NabokovfileKeyes.project_local_path] = nil
109
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
110
+ expect { validator.validate }.to raise_error("Project repo local path must be presented")
111
+ end
112
+ end
113
+
114
+ context "when the localizations is not a type of Hash" do
115
+ context "when string" do
116
+ it "raises an error" do
117
+ @valid_hash[Nabokov::NabokovfileKeyes.project_repo][Nabokov::NabokovfileKeyes.project_localization_file_paths] = "param:pam"
118
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
119
+ expect { validator.validate }.to raise_error("Localizations must be a type of Hash")
120
+ end
121
+ end
122
+
123
+ context "when array" do
124
+ it "raises an error" do
125
+ @valid_hash[Nabokov::NabokovfileKeyes.project_repo][Nabokov::NabokovfileKeyes.project_localization_file_paths] = ["key", "value"]
126
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
127
+ expect { validator.validate }.to raise_error("Localizations must be a type of Hash")
128
+ end
129
+ end
130
+
131
+ context "when number" do
132
+ it "raises an error" do
133
+ @valid_hash[Nabokov::NabokovfileKeyes.project_repo][Nabokov::NabokovfileKeyes.project_localization_file_paths] = 10
134
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
135
+ expect { validator.validate }.to raise_error("Localizations must be a type of Hash")
136
+ end
137
+ end
138
+ end
139
+
140
+ context "when the localizations array contains file that does not exist" do
141
+ it "raises an error" do
142
+ @valid_hash[Nabokov::NabokovfileKeyes.project_repo][Nabokov::NabokovfileKeyes.project_localization_file_paths] = { "en" => "spec/fixtures/en.strings",
143
+ "de" => "spec/fixtures/fr.strings" }
144
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
145
+ expect { validator.validate }.to raise_error("Couldn't find strings file at 'spec/fixtures/fr.strings'")
146
+ end
147
+ end
148
+
149
+ context "when the hash is valid" do
150
+ it "doesn't raise anything" do
151
+ validator = Nabokov::NabokovfileContentValidator.new(@valid_hash)
152
+ validator.validate
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,31 @@
1
+ require "nabokov/core/nabokovfile_keys"
2
+
3
+ describe Nabokov::NabokovfileKeyes do
4
+ it "has a valid localizations_repo key" do
5
+ expect(Nabokov::NabokovfileKeyes.localizations_repo).to eql("localizations_repo")
6
+ end
7
+
8
+ it "has a valid localizations_repo_url key" do
9
+ expect(Nabokov::NabokovfileKeyes.localizations_repo_url).to eql("url")
10
+ end
11
+
12
+ it "has a valid localizations_repo_master_branch key" do
13
+ expect(Nabokov::NabokovfileKeyes.localizations_repo_master_branch).to eql("master_branch")
14
+ end
15
+
16
+ it "has a valid git_repo_master_branch key" do
17
+ expect(Nabokov::NabokovfileKeyes.localizations_repo_master_branch).to eql("master_branch")
18
+ end
19
+
20
+ it "has a valid project_repo key" do
21
+ expect(Nabokov::NabokovfileKeyes.project_repo).to eql("project_repo")
22
+ end
23
+
24
+ it "has a valid project_local_path key" do
25
+ expect(Nabokov::NabokovfileKeyes.project_local_path).to eql("local_path")
26
+ end
27
+
28
+ it "has a valid project_localization_file_paths key" do
29
+ expect(Nabokov::NabokovfileKeyes.project_localization_file_paths).to eql("localizations")
30
+ end
31
+ end