localeapp 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -3
  3. data/CHANGELOG.md +12 -0
  4. data/README.md +9 -0
  5. data/bin/localeapp +141 -119
  6. data/features/add.feature +15 -49
  7. data/features/bad_command.feature +4 -3
  8. data/features/env_file.feature +7 -0
  9. data/features/environment.feature +7 -0
  10. data/features/help.feature +3 -4
  11. data/features/install.feature +19 -33
  12. data/features/install/write_env_file.feature +26 -0
  13. data/features/mv.feature +9 -5
  14. data/features/options/api_key.feature +6 -0
  15. data/features/pull.feature +15 -27
  16. data/features/push.feature +15 -28
  17. data/features/rm.feature +10 -5
  18. data/features/step_definitions/cli_steps.rb +13 -10
  19. data/features/step_definitions/execution_steps.rb +3 -0
  20. data/features/step_definitions/filesystem_steps.rb +12 -0
  21. data/features/step_definitions/output_steps.rb +10 -0
  22. data/features/support/env.rb +2 -2
  23. data/features/update.feature +20 -29
  24. data/lib/localeapp.rb +7 -0
  25. data/lib/localeapp/cli/install.rb +28 -15
  26. data/lib/localeapp/cli/pull.rb +2 -1
  27. data/lib/localeapp/cli/push.rb +2 -1
  28. data/lib/localeapp/cli/remove.rb +2 -1
  29. data/lib/localeapp/cli/rename.rb +2 -1
  30. data/lib/localeapp/configuration.rb +1 -1
  31. data/lib/localeapp/poller.rb +4 -1
  32. data/lib/localeapp/sender.rb +1 -0
  33. data/lib/localeapp/version.rb +1 -1
  34. data/spec/localeapp/cli/install_spec.rb +103 -63
  35. data/spec/localeapp/cli/pull_spec.rb +1 -1
  36. data/spec/localeapp/cli/push_spec.rb +1 -1
  37. data/spec/localeapp/cli/rename_spec.rb +1 -1
  38. metadata +10 -6
  39. data/.autotest +0 -4
  40. data/.rvmrc +0 -1
  41. data/init.rb +0 -1
@@ -1,7 +1,8 @@
1
- Feature: localeapp executable
2
- Scenario: Running a command that doesn't exist
3
- In order to warn of a bad command
1
+ Feature: Unknown command
2
+
3
+ Scenario: Reports an error when given unknown command
4
4
  When I run `localeapp foo`
5
+ Then the exit status must be 64
5
6
  Then the output should contain:
6
7
  """
7
8
  error: Unknown command 'foo'
@@ -0,0 +1,7 @@
1
+ Feature: Reading configuration from `.env' file
2
+
3
+ Scenario: Uses the API key from `.env' file
4
+ Given I have a valid project on localeapp.com with api key "MYAPIKEY"
5
+ And I have a .env file containing the api key "MYAPIKEY"
6
+ When I run `localeapp add foo.baz en:"test en content"`
7
+ Then the exit status must be 0
@@ -0,0 +1,7 @@
1
+ Feature: Reading configuration from environment
2
+
3
+ Scenario: Uses the API key set in current environment
4
+ Given I have a valid project on localeapp.com with api key "MYAPIKEY"
5
+ And I have a LOCALEAPP_API_KEY env variable set to "MYAPIKEY"
6
+ When I run `localeapp add foo.baz en:"test en content"`
7
+ Then the exit status must be 0
@@ -1,8 +1,7 @@
1
- Feature: Getting help
1
+ Feature: `help' command
2
2
 
3
- Scenario: Viewing help
4
- In order to see what options I have
5
- When I run `localeapp help`
3
+ Scenario: Shows help when given `help' command
4
+ When I successfully run `localeapp help`
6
5
  Then the output should contain:
7
6
  """
8
7
  localeapp [global options] command [command options]
@@ -1,9 +1,8 @@
1
- Feature: Installation
1
+ Feature: `install' command
2
2
 
3
- Scenario: Running Rails install
4
- In order to configure my project and check my api key is correct
3
+ Scenario: Installs rails configuration
5
4
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
6
- When I run `localeapp install MYAPIKEY`
5
+ When I successfully run `localeapp install MYAPIKEY`
7
6
  Then the output should contain:
8
7
  """
9
8
  Localeapp Install
@@ -13,14 +12,11 @@ Feature: Installation
13
12
  Project: Test Project
14
13
  Default Locale: en (English)
15
14
  """
16
- And help should not be displayed
17
- And a file named "config/initializers/localeapp.rb" should exist
18
- And the exit status should be 0
15
+ And a file named "config/initializers/localeapp.rb" should exist
19
16
 
20
- Scenario: Running standalone install
21
- In order to configure my non rails project and check my api key is correct
17
+ Scenario: Installs standalone configuration when given --standalone option
22
18
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
23
- When I run `localeapp install --standalone MYAPIKEY`
19
+ When I successfully run `localeapp install --standalone MYAPIKEY`
24
20
  Then the output should contain:
25
21
  """
26
22
  Localeapp Install
@@ -32,14 +28,11 @@ Feature: Installation
32
28
  Writing configuration file to .localeapp/config.rb
33
29
  WARNING: please create the locales directory. Your translation data will be stored there.
34
30
  """
35
- And help should not be displayed
36
- And a file named ".localeapp/config.rb" should exist
37
- And the exit status should be 0
31
+ And a file named ".localeapp/config.rb" should exist
38
32
 
39
- Scenario: Running github install
40
- In order to configure my public github project and check my api key is correct
33
+ Scenario: Installs standalone config and other files when given --github option
41
34
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
42
- When I run `localeapp install --github MYAPIKEY`
35
+ When I successfully run `localeapp install --github MYAPIKEY`
43
36
  Then the output should contain:
44
37
  """
45
38
  Localeapp Install
@@ -50,16 +43,13 @@ Feature: Installation
50
43
  NOTICE: you probably want to add .localeapp to your .gitignore file
51
44
  Writing configuration file to .localeapp/config.rb
52
45
  """
53
- And help should not be displayed
54
- And a file named ".localeapp/config.rb" should exist
55
- And a file named ".gitignore" should exist
56
- And a file named "README.md" should exist
57
- And the exit status should be 0
46
+ And a file named ".localeapp/config.rb" should exist
47
+ And a file named ".gitignore" should exist
48
+ And a file named "README.md" should exist
58
49
 
59
- Scenario: Running heroku install with no api key
60
- In order to configure my project to use localeapp as a heroku addon
50
+ Scenario: Installs heroku config files when given --heroku option
61
51
  Given I have a valid heroku project
62
- When I run `localeapp install --heroku`
52
+ When I successfully run `localeapp install --heroku`
63
53
  Then the output should contain:
64
54
  """
65
55
  Localeapp Install
@@ -73,15 +63,13 @@ Feature: Installation
73
63
  Project: Test Project
74
64
  Default Locale: en (English)
75
65
  """
76
- And help should not be displayed
77
- And a file named "config/initializers/localeapp.rb" should exist
78
- And the file "config/initializers/localeapp.rb" should contain "config.api_key = ENV['LOCALEAPP_API_KEY']"
79
- And the exit status should be 0
66
+ And a file named "config/initializers/localeapp.rb" should exist
67
+ And the file "config/initializers/localeapp.rb" should contain "config.api_key = ENV['LOCALEAPP_API_KEY']"
80
68
 
81
- Scenario: Running install with bad api key
82
- In order to configure my project and check my api key is correct
69
+ Scenario: Reports an error when given incorrect API key
83
70
  Given I have a valid project on localeapp.com but an incorrect api key "BADAPIKEY"
84
71
  When I run `localeapp install BADAPIKEY`
72
+ Then the exit status must be 1
85
73
  Then the output should contain:
86
74
  """
87
75
  Localeapp Install
@@ -89,6 +77,4 @@ Feature: Installation
89
77
  Checking API key: BADAPIKEY
90
78
  ERROR: Project not found
91
79
  """
92
- And help should not be displayed
93
- And a file named "config/initializers/localeapp.rb" should not exist
94
- And the exit status should not be 0
80
+ And a file named "config/initializers/localeapp.rb" should not exist
@@ -0,0 +1,26 @@
1
+ Feature: `install' command with `-e' option
2
+
3
+ Scenario: describes `-e' option in the `install' command usage
4
+ When I successfully run `localeapp help install`
5
+ Then the output must match /-e.*--\[no-\]write-env-file.*write API key to/i
6
+
7
+ Scenario: writes API key to `.env' file when given `-e' option
8
+ Given I have a valid project on localeapp.com with api key "MYAPIKEY"
9
+ When I successfully run `localeapp install MYAPIKEY -e`
10
+ Then the file ".env" must contain exactly:
11
+ """
12
+ LOCALEAPP_API_KEY=MYAPIKEY
13
+ """
14
+
15
+ Scenario: preserves `.env' file content when given `-e' option
16
+ Given I have a valid project on localeapp.com with api key "MYAPIKEY"
17
+ And a file ".env" with content:
18
+ """
19
+ FOO=BAR
20
+ """
21
+ When I successfully run `localeapp install MYAPIKEY -e`
22
+ Then the file ".env" must contain exactly:
23
+ """
24
+ FOO=BAR
25
+ LOCALEAPP_API_KEY=MYAPIKEY
26
+ """
data/features/mv.feature CHANGED
@@ -1,10 +1,9 @@
1
- Feature: Renaming a translation from the command line
1
+ Feature: `mv' command
2
2
 
3
- Scenario: Running mv
4
- In order to rename an existing key
3
+ Scenario: Renames the given translation
5
4
  Given I have a valid project on localeapp.com with api key "MYAPIKEY" and the translation key "foo.bar"
6
- And an initializer file
7
- When I run `localeapp mv foo.bar foo.baz`
5
+ And an initializer file
6
+ When I successfully run `localeapp mv foo.bar foo.baz`
8
7
  Then the output should contain:
9
8
  """
10
9
  Localeapp mv
@@ -13,3 +12,8 @@ Feature: Renaming a translation from the command line
13
12
  Success!
14
13
  """
15
14
 
15
+ Scenario: Reports an error when the given API key is incorrect
16
+ Given no project exist on localeapp.com with API key "MYAPIKEY"
17
+ When I run `localeapp -k MYAPIKEY mv foo.bar foo.baz`
18
+ Then the exit status must be 70
19
+ And the output must match /error.+404/i
@@ -0,0 +1,6 @@
1
+ Feature: `-k' global option (`--api-key')
2
+
3
+ Scenario: Uses the API key given as `-k' option
4
+ Given I have a valid project on localeapp.com with api key "MYAPIKEY"
5
+ When I run `localeapp -k MYAPIKEY add foo en:"en content"`
6
+ Then the exit status must be 0
@@ -1,11 +1,11 @@
1
- Feature: Pulling all translation
1
+ Feature: `pull' command
2
2
 
3
- Scenario: Running pull
4
- In order to retrieve my translations
3
+ Scenario: Pulls translations
5
4
  Given I have a translations on localeapp.com for the project with api key "MYAPIKEY"
6
- And an initializer file
7
- And a directory named "config/locales"
8
- When I run `localeapp pull`
5
+ And an initializer file
6
+ And a directory named "config/locales"
7
+ And a directory named "log"
8
+ When I successfully run `localeapp pull`
9
9
  Then the output should contain:
10
10
  """
11
11
  Localeapp Pull
@@ -15,32 +15,20 @@ Feature: Pulling all translation
15
15
  Updating backend:
16
16
  Success!
17
17
  """
18
- And help should not be displayed
19
- And a file named "config/locales/en.yml" should exist
18
+ And a file named "config/locales/en.yml" should exist
20
19
 
21
- Scenario: Running pull without having a locales dir
22
- In order to retreive my translations
20
+ Scenario: Reports an error when locales directory is missing
23
21
  Given I have a translations on localeapp.com for the project with api key "MYAPIKEY"
24
- And an initializer file
22
+ And an initializer file
25
23
  When I run `localeapp pull`
26
- Then the output should contain:
24
+ Then the exit status must be 1
25
+ And the output should contain:
27
26
  """
28
27
  Could not write locale file, please make sure that config/locales exists and is writable
29
28
  """
30
29
 
31
- Scenario: Running pull with no initializer file, passing the key on the command line
32
- In order to retrieve my translations
33
- Given I have a translations on localeapp.com for the project with api key "MYAPIKEY"
34
- And a directory named "config/locales"
30
+ Scenario: Reports an error when the given API key is incorrect
31
+ Given no project exist on localeapp.com with API key "MYAPIKEY"
35
32
  When I run `localeapp -k MYAPIKEY pull`
36
- Then the output should contain:
37
- """
38
- Localeapp Pull
39
-
40
- Fetching translations:
41
- Success!
42
- Updating backend:
43
- Success!
44
- """
45
- And help should not be displayed
46
- And a file named "config/locales/en.yml" should exist
33
+ Then the exit status must be 70
34
+ And the output must match /error.+404/i
@@ -1,11 +1,10 @@
1
- Feature: Pushing existing translation to localeapp
1
+ Feature: `push' command
2
2
 
3
- Scenario: Running push on a file
4
- In order to send my translations
3
+ Scenario: Pushes translations in a specific locales file
5
4
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
6
- And an initializer file
7
- And an empty file named "config/locales/en.yml"
8
- When I run `localeapp push config/locales/en.yml`
5
+ And an initializer file
6
+ And an empty file named "config/locales/en.yml"
7
+ When I successfully run `localeapp push config/locales/en.yml`
9
8
  Then the output should contain:
10
9
  """
11
10
  Localeapp Push
@@ -15,15 +14,13 @@ Feature: Pushing existing translation to localeapp
15
14
 
16
15
  config/locales/en.yml queued for processing.
17
16
  """
18
- And help should not be displayed
19
17
 
20
- Scenario: Running push on a directory
21
- In order to send my translations
18
+ Scenario: Pushes all locales within given directory
22
19
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
23
- And an initializer file
24
- And an empty file named "config/locales/en.yml"
25
- And an empty file named "config/locales/es.yml"
26
- When I run `localeapp push config/locales`
20
+ And an initializer file
21
+ And an empty file named "config/locales/en.yml"
22
+ And an empty file named "config/locales/es.yml"
23
+ When I successfully run `localeapp push config/locales`
27
24
  Then the output should contain:
28
25
  """
29
26
  Localeapp Push
@@ -38,20 +35,10 @@ Feature: Pushing existing translation to localeapp
38
35
 
39
36
  config/locales/es.yml queued for processing.
40
37
  """
41
- And help should not be displayed
42
38
 
43
- Scenario: Running push on a file with no initializer file, passing the key on the command line
44
- In order to send my translations
45
- Given I have a valid project on localeapp.com with api key "MYAPIKEY"
46
- And an empty file named "config/locales/en.yml"
39
+ Scenario: Reports an error when the given API key is incorrect
40
+ Given no project exist on localeapp.com with API key "MYAPIKEY"
41
+ And an empty file named "config/locales/en.yml"
47
42
  When I run `localeapp -k MYAPIKEY push config/locales/en.yml`
48
- Then the output should contain:
49
- """
50
- Localeapp Push
51
-
52
- Pushing file en.yml:
53
- Success!
54
-
55
- config/locales/en.yml queued for processing.
56
- """
57
- And help should not be displayed
43
+ Then the exit status must be 70
44
+ And the output must match /error.+404/i
data/features/rm.feature CHANGED
@@ -1,10 +1,9 @@
1
- Feature: Removing a translation from the command line
1
+ Feature: `rm' command
2
2
 
3
- Scenario: Running rm
4
- In order to remove an existing key
3
+ Scenario: Removes the given key
5
4
  Given I have a valid project on localeapp.com with api key "MYAPIKEY" and the translation key "foo.bar"
6
- And an initializer file
7
- When I run `localeapp rm foo.bar`
5
+ And an initializer file
6
+ When I successfully run `localeapp rm foo.bar`
8
7
  Then the output should contain:
9
8
  """
10
9
  Localeapp rm
@@ -12,3 +11,9 @@ Feature: Removing a translation from the command line
12
11
  Remove key: foo.bar
13
12
  Success!
14
13
  """
14
+
15
+ Scenario: Reports an error when the given API key is incorrect
16
+ Given no project exist on localeapp.com with API key "MYAPIKEY"
17
+ When I run `localeapp -k MYAPIKEY rm foo.bar`
18
+ Then the exit status must be 70
19
+ And the output must match /error.+404/i
@@ -1,11 +1,23 @@
1
1
  require 'net/http'
2
2
  require 'time'
3
3
 
4
+ Given /^no project exist on localeapp\.com with API key "([^"]+)"$/ do |api_key|
5
+ add_fake_web_uri :any, /\Ahttps:\/\/api\.localeapp\.com\/.*/,
6
+ [404, "Not Found"],
7
+ ""
8
+ end
9
+
4
10
  When /^I have a valid project on localeapp\.com with api key "([^"]*)"$/ do |api_key|
5
11
  uri = "https://api.localeapp.com/v1/projects/#{api_key}.json"
6
12
  body = valid_project_data.to_json
7
13
  add_fake_web_uri(:get, uri, ['200', 'OK'], body)
8
- add_fake_web_uri(:post, "https://api.localeapp.com/v1/projects/#{api_key}/import/", ['202', 'OK'], '')
14
+ add_fake_web_uri(
15
+ :post,
16
+ "https://api.localeapp.com/v1/projects/#{api_key}/import/",
17
+ %w[202 OK],
18
+ JSON.generate(id: 12345),
19
+ "Content-Type" => "application/json; charset=utf-8"
20
+ )
9
21
  add_fake_web_uri(:post, "https://api.localeapp.com/v1/projects/#{api_key}/translations/missing.json", ["202", "OK"], '')
10
22
  end
11
23
 
@@ -71,15 +83,6 @@ When /^an initializer file$/ do
71
83
  }
72
84
  end
73
85
 
74
- When /^help should not be displayed$/ do
75
- steps %Q{
76
- And the output should not contain:
77
- """
78
- Usage: localeapp COMMAND [options]
79
- """
80
- }
81
- end
82
-
83
86
  When /^the timestamp is (\d+) months? old$/ do |months|
84
87
  @timestamp = Time.now.to_i - months.to_i * 2592000
85
88
  steps %Q{
@@ -0,0 +1,3 @@
1
+ Then /^the exit status must be (\d+)$/ do |status|
2
+ expect(last_command_started).to have_exit_status status.to_i
3
+ end
@@ -0,0 +1,12 @@
1
+ Given /^a file "([^"]+)" with content:$/ do |path, content|
2
+ cd ?. do
3
+ File.write(path, content + $/)
4
+ end
5
+ end
6
+
7
+
8
+ Then /^the file "([^"]+)" must contain exactly:$/ do |path, content|
9
+ cd ?. do
10
+ expect(File.read(path)).to eq content + $/
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ Then /^the output must match \/([^\/]+)\/([imx]*)$/ do |pattern, options|
2
+ regexp = Regexp.new(pattern, options.each_char.inject(0) do |m, e|
3
+ m | case e
4
+ when ?i then Regexp::IGNORECASE
5
+ when ?m then Regexp::MULTILINE
6
+ when ?x then Regexp::EXTENDED
7
+ end
8
+ end)
9
+ expect(last_command_started.output).to match regexp
10
+ end
@@ -6,7 +6,7 @@ World(LocaleappIntegrationData)
6
6
 
7
7
  module FakeWebHelper
8
8
  def add_fake_web_uri(method, uri, status, body, headers = {})
9
- fakes = JSON.parse(aruba.environment['FAKE_WEB_FAKES'] || '[]')
9
+ fakes = YAML.load(aruba.environment['FAKE_WEB_FAKES'] || '[]')
10
10
  fakes << {
11
11
  'method' => method,
12
12
  'uri' => uri,
@@ -14,7 +14,7 @@ module FakeWebHelper
14
14
  'body' => body,
15
15
  'headers' => headers
16
16
  }
17
- set_environment_variable 'FAKE_WEB_FAKES', fakes.to_json
17
+ set_environment_variable 'FAKE_WEB_FAKES', YAML.dump(fakes)
18
18
  end
19
19
  end
20
20
  World(FakeWebHelper)
@@ -1,38 +1,29 @@
1
- Feature: Getting new translations
1
+ Feature: `update' command
2
2
 
3
- Scenario: Running update
4
- In order to receive the translations that have been updated since the last check
3
+ Scenario: Fetches translations
5
4
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
6
- And an initializer file
7
- And the timestamp is 2 months old
8
- And new translations for the api key "MYAPIKEY" since last fetch with time "60" seconds later
9
- And a directory named "config/locales"
10
- When I run `localeapp update`
5
+ And an initializer file
6
+ And the timestamp is 2 months old
7
+ And new translations for the api key "MYAPIKEY" since last fetch with time "60" seconds later
8
+ And a directory named "config/locales"
9
+ When I successfully run `localeapp update`
11
10
  Then translations should be fetched since last fetch only
12
- And help should not be displayed
13
- And a file named "config/locales/en.yml" should exist
14
- # check the content here
15
- # and the localeapp.yml file
11
+ And a file named "config/locales/en.yml" should exist
16
12
 
17
- Scenario: Running update with no initializer file, passing the key on the command line
18
- In order to receive the translations that have been updated since the last check
13
+ Scenario: Reports an error when timestamp is too old
19
14
  Given I have a valid project on localeapp.com with api key "MYAPIKEY"
20
- And the timestamp is 2 months old
21
- And new translations for the api key "MYAPIKEY" since last fetch with time "60" seconds later
22
- And a directory named "config/locales"
23
- When I run `localeapp -k MYAPIKEY update`
24
- Then translations should be fetched since last fetch only
25
- And help should not be displayed
26
- And a file named "config/locales/en.yml" should exist
27
-
28
- Scenario: Running update with a too old timestamp
29
- In order to receive the translations that have been updated since the last check
30
- Given I have a valid project on localeapp.com with api key "MYAPIKEY"
31
- And an initializer file
32
- And the timestamp is 8 months old
33
- When I run `localeapp update`
15
+ And an initializer file
16
+ And the timestamp is 8 months old
17
+ When I successfully run `localeapp update`
34
18
  Then the output should contain:
35
19
  """
36
20
  Timestamp is missing or too old
37
21
  """
38
- And help should not be displayed
22
+
23
+ Scenario: Reports an error when the given API key is incorrect
24
+ Given no project exist on localeapp.com with API key "MYAPIKEY"
25
+ And the timestamp is 2 months old
26
+ And a directory named "config/locales"
27
+ When I run `localeapp -k MYAPIKEY update`
28
+ Then the exit status must be 70
29
+ And the output must match /error.+404/i