neverbounce-cli 1.0.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 (83) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +8 -0
  3. data/.gitignore +21 -0
  4. data/.rspec +4 -0
  5. data/.rubocop.yml +1161 -0
  6. data/.travis.yml +27 -0
  7. data/.yardopts +2 -0
  8. data/Gemfile +19 -0
  9. data/Gemfile.lock +60 -0
  10. data/LICENSE +9 -0
  11. data/README.md +138 -0
  12. data/exe/nb-account-info +5 -0
  13. data/exe/nb-jobs-create +5 -0
  14. data/exe/nb-jobs-delete +5 -0
  15. data/exe/nb-jobs-download +5 -0
  16. data/exe/nb-jobs-parse +5 -0
  17. data/exe/nb-jobs-results +5 -0
  18. data/exe/nb-jobs-search +5 -0
  19. data/exe/nb-jobs-start +5 -0
  20. data/exe/nb-jobs-status +5 -0
  21. data/exe/nb-single-check +5 -0
  22. data/lib/never_bounce/cli/feature/basic_initialize.rb +20 -0
  23. data/lib/never_bounce/cli/feature/eigencache.rb +47 -0
  24. data/lib/never_bounce/cli/feature/envars/examples_mapper.rb +38 -0
  25. data/lib/never_bounce/cli/feature/envars/item.rb +41 -0
  26. data/lib/never_bounce/cli/feature/envars.rb +82 -0
  27. data/lib/never_bounce/cli/feature/igetset.rb +41 -0
  28. data/lib/never_bounce/cli/feature/require_attr.rb +25 -0
  29. data/lib/never_bounce/cli/script/account_info.rb +85 -0
  30. data/lib/never_bounce/cli/script/base.rb +101 -0
  31. data/lib/never_bounce/cli/script/error.rb +16 -0
  32. data/lib/never_bounce/cli/script/feature/requires_job_id.rb +28 -0
  33. data/lib/never_bounce/cli/script/feature/uses_pagination.rb +45 -0
  34. data/lib/never_bounce/cli/script/jobs_create/supplied_input_parser.rb +48 -0
  35. data/lib/never_bounce/cli/script/jobs_create.rb +157 -0
  36. data/lib/never_bounce/cli/script/jobs_delete.rb +55 -0
  37. data/lib/never_bounce/cli/script/jobs_download.rb +44 -0
  38. data/lib/never_bounce/cli/script/jobs_parse.rb +73 -0
  39. data/lib/never_bounce/cli/script/jobs_results.rb +105 -0
  40. data/lib/never_bounce/cli/script/jobs_search.rb +135 -0
  41. data/lib/never_bounce/cli/script/jobs_start.rb +73 -0
  42. data/lib/never_bounce/cli/script/jobs_status.rb +96 -0
  43. data/lib/never_bounce/cli/script/manifest.rb +22 -0
  44. data/lib/never_bounce/cli/script/meaningful.rb +233 -0
  45. data/lib/never_bounce/cli/script/request_maker.rb +169 -0
  46. data/lib/never_bounce/cli/script/single_check.rb +146 -0
  47. data/lib/never_bounce/cli/script/table.rb +43 -0
  48. data/lib/never_bounce/cli/user_config/file_content.rb +66 -0
  49. data/lib/never_bounce/cli/user_config.rb +51 -0
  50. data/lib/never_bounce/cli/version.rb +4 -0
  51. data/lib/neverbounce-cli.rb +3 -0
  52. data/neverbounce-cli.gemspec +24 -0
  53. data/spec/lib/never_bounce/cli/feature/basic_initialize_spec.rb +26 -0
  54. data/spec/lib/never_bounce/cli/feature/eigencache_spec.rb +28 -0
  55. data/spec/lib/never_bounce/cli/feature/envars/examples_mapper_spec.rb +26 -0
  56. data/spec/lib/never_bounce/cli/feature/envars/item_spec.rb +9 -0
  57. data/spec/lib/never_bounce/cli/feature/envars_spec.rb +55 -0
  58. data/spec/lib/never_bounce/cli/feature/igetset_spec.rb +45 -0
  59. data/spec/lib/never_bounce/cli/feature/require_attr_spec.rb +25 -0
  60. data/spec/lib/never_bounce/cli/script/account_info_spec.rb +65 -0
  61. data/spec/lib/never_bounce/cli/script/base_spec.rb +56 -0
  62. data/spec/lib/never_bounce/cli/script/feature/requires_job_id_spec.rb +17 -0
  63. data/spec/lib/never_bounce/cli/script/feature/uses_pagination_spec.rb +21 -0
  64. data/spec/lib/never_bounce/cli/script/jobs_create/supplied_input_parser_spec.rb +35 -0
  65. data/spec/lib/never_bounce/cli/script/jobs_create_spec.rb +118 -0
  66. data/spec/lib/never_bounce/cli/script/jobs_delete_spec.rb +33 -0
  67. data/spec/lib/never_bounce/cli/script/jobs_download_spec.rb +37 -0
  68. data/spec/lib/never_bounce/cli/script/jobs_parse_spec.rb +45 -0
  69. data/spec/lib/never_bounce/cli/script/jobs_results_spec.rb +40 -0
  70. data/spec/lib/never_bounce/cli/script/jobs_search_spec.rb +59 -0
  71. data/spec/lib/never_bounce/cli/script/jobs_start_spec.rb +45 -0
  72. data/spec/lib/never_bounce/cli/script/jobs_status_spec.rb +37 -0
  73. data/spec/lib/never_bounce/cli/script/manifest_spec.rb +6 -0
  74. data/spec/lib/never_bounce/cli/script/meaningful_spec.rb +93 -0
  75. data/spec/lib/never_bounce/cli/script/request_maker_spec.rb +67 -0
  76. data/spec/lib/never_bounce/cli/script/single_check_spec.rb +94 -0
  77. data/spec/lib/never_bounce/cli/script/spec_helper.rb +59 -0
  78. data/spec/lib/never_bounce/cli/script/table_spec.rb +6 -0
  79. data/spec/lib/never_bounce/cli/user_config/file_content_spec.rb +43 -0
  80. data/spec/lib/never_bounce/cli/user_config_spec.rb +12 -0
  81. data/spec/lib/never_bounce/cli_spec.rb +6 -0
  82. data/spec/spec_helper.rb +51 -0
  83. metadata +193 -0
@@ -0,0 +1,118 @@
1
+
2
+ module NeverBounce; module CLI; module Script
3
+ describe JobsCreate do
4
+ include_dir_context __dir__
5
+
6
+ def margv(*args)
7
+ ["API_KEY=abc"] + args
8
+ end
9
+
10
+ it_behaves_like "instantiatable"
11
+ it_behaves_like "a script supporting `--help`", signatures: [/nb-jobs-create/, /AUTO_PARSE/, /AUTO_START/, /FILENAME/, /REMOTE_INPUT/, /RUN_SAMPLE/, /SUPPLIED_INPUT/]
12
+
13
+ describe "mode attributes" do
14
+ describe "#auto_parse" do
15
+ let(:m) { :auto_parse }
16
+ it "generally works" do
17
+ expect(newo(env: {}).send(m)).to be nil
18
+ expect(newo(env: {"AUTO_PARSE" => "y"}).send(m)).to be true
19
+ expect(newo(env: {"AUTO_PARSE" => "n"}).send(m)).to be false
20
+ end
21
+ end
22
+
23
+ describe "#auto_start" do
24
+ let(:m) { :auto_start }
25
+ it "generally works" do
26
+ expect(newo(env: {}).send(m)).to be nil
27
+ expect(newo(env: {"AUTO_START" => "y"}).send(m)).to be true
28
+ expect(newo(env: {"AUTO_START" => "n"}).send(m)).to be false
29
+ end
30
+ end
31
+
32
+ describe "#run_sample" do
33
+ it "generally works" do
34
+ expect(newo(env: {}).run_sample).to be nil
35
+ expect(newo(env: {"RUN_SAMPLE" => "y"}).run_sample).to be true
36
+ expect(newo(env: {"RUN_SAMPLE" => "n"}).run_sample).to be false
37
+ end
38
+ end
39
+ end # describe "mode attributes"
40
+
41
+ describe "#input_location" do
42
+ let(:m) { :input_location }
43
+ it "generally works" do
44
+ r = newo(env: {})
45
+ expect { r.send(m) }.to raise_error(UsageError, "Input not given, use `REMOTE_INPUT=` or `SUPPLIED_INPUT=`")
46
+ r = newo(env: {"REMOTE_INPUT" => "remote_input"})
47
+ expect(r.send(m)).to eq "remote_url"
48
+ r = newo(env: {"SUPPLIED_INPUT" => "supplied_input"})
49
+ expect(r.send(m)).to eq "supplied"
50
+ r = newo(env: {"REMOTE_INPUT" => "remote_input", "SUPPLIED_INPUT" => "supplied_input"})
51
+ expect { r.send(m) }.to raise_error(UsageError, "`REMOTE_INPUT` and `SUPPLIED_INPUT` can't both be given")
52
+ end
53
+ end
54
+
55
+ describe "attributes" do
56
+ describe "#filename" do
57
+ it "has a time-based default value" do
58
+ r = newo(now: Time.new(2017, 12, 18, 11, 22, 33))
59
+ expect(r.filename).to eq "20171218-112233.csv"
60
+ end
61
+
62
+ it "generally works" do
63
+ r = newo(env: {"FILENAME" => "abc"})
64
+ expect(r.filename).to eq "abc"
65
+ end
66
+ end
67
+
68
+ describe "#remote_input" do
69
+ it "generally works" do
70
+ expect(newo(env: {}).remote_input).to be nil
71
+ expect(newo(env: {"REMOTE_INPUT" => "remote_input"}).remote_input).to eq "remote_input"
72
+ end
73
+ end
74
+ end # describe "attributes"
75
+
76
+ describe "#request_curl" do
77
+ context "when remote input" do
78
+ it "generally works" do
79
+ r = goodo(argv: margv(
80
+ "AUTO_PARSE=y",
81
+ "AUTO_START=y",
82
+ "FILENAME=filename",
83
+ "REMOTE_INPUT=remote_input",
84
+ "RUN_SAMPLE=y",
85
+ ))
86
+ expect(r.request_curl).to eq ["--request", "POST", "--url", "https://api.neverbounce.com/v4/jobs/create", "--header", "Content-Type: application/json", "--data-binary", "{\"input\":\"remote_input\",\"input_location\":\"remote_url\",\"filename\":\"filename\",\"key\":\"abc\",\"auto_start\":true,\"auto_parse\":true,\"run_sample\":true}"]
87
+ end
88
+ end
89
+
90
+ context "when supplied input" do
91
+ it "generally works" do
92
+ r = goodo(argv: margv(
93
+ "AUTO_PARSE=y",
94
+ "AUTO_START=y",
95
+ "FILENAME=filename",
96
+ "RUN_SAMPLE=y",
97
+ "SUPPLIED_INPUT=alice@isp.com;bob.smith@gmail.com",
98
+ ))
99
+ expect(r.request_curl).to eq ["--request", "POST", "--url", "https://api.neverbounce.com/v4/jobs/create", "--header", "Content-Type: application/json", "--data-binary", "{\"input\":[[\"alice@isp.com\",\"\"],[\"bob.smith@gmail.com\",\"\"]],\"input_location\":\"supplied\",\"filename\":\"filename\",\"key\":\"abc\",\"auto_start\":true,\"auto_parse\":true,\"run_sample\":true}"]
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "output" do
105
+ it "generally works" do
106
+ r = goodo(argv: margv("SUPPLIED_INPUT=alice@isp.com")).tap do |_|
107
+ _.session.server_content_type = "application/json"
108
+ _.session.server_raw = '{"status":"success","job_id":348530,"execution_time":602}'
109
+ end
110
+ expect { r.main }.not_to raise_error
111
+ lines = r.stdout.tap(&:rewind).to_a
112
+ expect(lines).to be_any { |s| s =~ /Response:/ }
113
+ expect(lines).to be_any { |s| s =~ cell("JobId") }
114
+ expect(lines).to be_any { |s| s =~ cell("ExecTime") }
115
+ end
116
+ end
117
+ end
118
+ end; end; end
@@ -0,0 +1,33 @@
1
+
2
+ module NeverBounce; module CLI; module Script
3
+ describe JobsDelete do
4
+ include_dir_context __dir__
5
+
6
+ def margv(*args)
7
+ ["API_KEY=abc", "ID=12"] + args
8
+ end
9
+
10
+ it_behaves_like "instantiatable"
11
+ it_behaves_like "a script supporting `--help`", signatures: [/nb-jobs-delete/, /ID/]
12
+
13
+ describe "#request_curl" do
14
+ it "generally works" do
15
+ r = goodo(argv: margv)
16
+ expect(r.request_curl).to eq ["--request", "POST", "--url", "https://api.neverbounce.com/v4/jobs/delete", "--header", "Content-Type: application/json", "--data-binary", "{\"job_id\":\"12\",\"key\":\"abc\"}"]
17
+ end
18
+ end
19
+
20
+ describe "output" do
21
+ it "generally works" do
22
+ r = goodo(argv: margv).tap do |_|
23
+ _.session.server_content_type = "application/json"
24
+ _.session.server_raw = '{"status":"success","execution_time":66}'
25
+ end
26
+ expect { r.main }.not_to raise_error
27
+ lines = r.stdout.tap(&:rewind).to_a
28
+ expect(lines).to be_any { |s| s =~ /Response:/ }
29
+ expect(lines).to be_any { |s| s =~ cell("ExecTime") }
30
+ end
31
+ end
32
+ end
33
+ end; end; end
@@ -0,0 +1,37 @@
1
+
2
+ module NeverBounce; module CLI; module Script
3
+ describe JobsDownload do
4
+ include_dir_context __dir__
5
+
6
+ def margv(*args)
7
+ ["API_KEY=abc", "ID=12"] + args
8
+ end
9
+
10
+ it_behaves_like "instantiatable"
11
+ it_behaves_like "a script supporting `--help`", signatures: [/nb-jobs-download/, /ID/]
12
+
13
+ describe "#request_curl" do
14
+ it "generally works" do
15
+ r = goodo(argv: margv)
16
+ expect(r.request_curl).to eq ["--request", "GET", "--url", "https://api.neverbounce.com/v4/jobs/download", "--header", "Content-Type: application/json", "--data-binary", "{\"job_id\":\"12\",\"key\":\"abc\"}"]
17
+ end
18
+ end
19
+
20
+ describe "output" do
21
+ it "generally works" do
22
+ r = goodo(argv: margv).tap do |_|
23
+ # NOTE: Raw content is actually multiline.
24
+ _.session.server_content_type = "application/octet-stream"
25
+ _.session.server_raw = 'id,email,name,email_status
26
+ "12345","support@neverbounce.com","Fred McValid",valid
27
+ "12346","invalid@neverbounce.com","Bob McInvalid",invalid'
28
+ end
29
+ expect { r.main }.not_to raise_error
30
+ lines = r.stdout.tap(&:rewind).to_a
31
+ expect(lines).to be_any { |s| s =~ /id,email,name,email_status/ }
32
+ expect(lines).to be_any { |s| s =~ /"Fred McValid"/ }
33
+ expect(lines).to be_any { |s| s =~ /"Bob McInvalid"/ }
34
+ end
35
+ end
36
+ end
37
+ end; end; end
@@ -0,0 +1,45 @@
1
+
2
+ module NeverBounce; module CLI; module Script
3
+ describe JobsParse do
4
+ include_dir_context __dir__
5
+
6
+ def margv(*args)
7
+ ["API_KEY=abc", "ID=12"] + args
8
+ end
9
+
10
+ it_behaves_like "instantiatable"
11
+ it_behaves_like "a script supporting `--help`", signatures: [/nb-jobs-parse/, /ID/, /AUTO_START/]
12
+
13
+ describe "mode attributes" do
14
+ describe "#auto_start" do
15
+ let(:m) { :auto_start }
16
+ it "generally works" do
17
+ expect(newo(env: {}).send(m)).to be nil
18
+ expect(newo(env: {"AUTO_START" => "y"}).send(m)).to be true
19
+ expect(newo(env: {"AUTO_START" => "n"}).send(m)).to be false
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#request_curl" do
25
+ it "generally works" do
26
+ r = goodo(argv: margv("AUTO_START=y"))
27
+ expect(r.request_curl).to eq ["--request", "POST", "--url", "https://api.neverbounce.com/v4/jobs/parse", "--header", "Content-Type: application/json", "--data-binary", "{\"job_id\":\"12\",\"key\":\"abc\",\"auto_start\":true}"]
28
+ end
29
+ end
30
+
31
+ describe "output" do
32
+ it "generally works" do
33
+ r = goodo(argv: margv).tap do |_|
34
+ _.session.server_content_type = "application/json"
35
+ _.session.server_raw = '{"status":"success","queue_id":"NB-PQ-598B5ED572898","execution_time":25}'
36
+ end
37
+ expect { r.main }.not_to raise_error
38
+ lines = r.stdout.tap(&:rewind).to_a
39
+ expect(lines).to be_any { |s| s =~ /Response:/ }
40
+ expect(lines).to be_any { |s| s =~ cell("QueueId") }
41
+ expect(lines).to be_any { |s| s =~ cell("ExecTime") }
42
+ end
43
+ end
44
+ end
45
+ end; end; end
@@ -0,0 +1,40 @@
1
+
2
+ module NeverBounce; module CLI; module Script
3
+ describe JobsResults do
4
+ include_dir_context __dir__
5
+
6
+ def margv(*args)
7
+ ["API_KEY=abc", "ID=12"] + args
8
+ end
9
+
10
+ it_behaves_like "instantiatable"
11
+ it_behaves_like "a script supporting `--help`", signatures: [/nb-jobs-results/, /PAGE/, /PER_PAGE/]
12
+
13
+ describe "#request_curl" do
14
+ it "generally works" do
15
+ r = goodo(argv: margv)
16
+ expect(r.request_curl).to eq ["--request", "GET", "--url", "https://api.neverbounce.com/v4/jobs/results", "--header", "Content-Type: application/json", "--data-binary", "{\"job_id\":\"12\",\"key\":\"abc\",\"items_per_page\":1000,\"page\":1}"]
17
+ end
18
+ end
19
+
20
+ describe "output" do
21
+ it "generally works" do
22
+ r = goodo(argv: margv).tap do |_|
23
+ _.session.server_content_type = "application/json"
24
+ _.session.server_raw = '{"status":"success","total_results":3,"total_pages":1,"query":{"job_id":274226,"valids":1,"invalids":1,"disposables":1,"catchalls":1,"unknowns":1,"page":1,"items_per_page":1000},"results":[{"data":{"email":"email","id":"id","name":"name"},"verification":{"result":"invalid","flags":[],"suggested_correction":"","address_info":{"original_email":"email","normalized_email":"","addr":"","alias":"","host":"","fqdn":"","domain":"","subdomain":"","tld":""}}},{"data":{"email":"support@neverbounce.com","id":"12345","name":"Fred McValid"},"verification":{"result":"valid","flags":["has_dns","has_dns_mx","role_account","smtp_connectable"],"suggested_correction":"","address_info":{"original_email":"support@neverbounce.com","normalized_email":"support@neverbounce.com","addr":"support","alias":"","host":"neverbounce.com","fqdn":"neverbounce.com","domain":"neverbounce","subdomain":"","tld":"com"}}},{"data":{"email":"invalid@neverbounce.com","id":"12346","name":"Bob McInvalid"},"verification":{"result":"invalid","flags":["has_dns","has_dns_mx","smtp_connectable"],"suggested_correction":"","address_info":{"original_email":"invalid@neverbounce.com","normalized_email":"invalid@neverbounce.com","addr":"invalid","alias":"","host":"neverbounce.com","fqdn":"neverbounce.com","domain":"neverbounce","subdomain":"","tld":"com"}}}],"execution_time":53}'
25
+ end
26
+ expect { r.main }.not_to raise_error
27
+ lines = r.stdout.tap(&:rewind).to_a
28
+ expect(lines).to be_any { |s| s =~ /Response:/ }
29
+ expect(lines).to be_any { |s| s =~ cell("nPages") }
30
+ expect(lines).to be_any { |s| s =~ cell("ExecTime") }
31
+ expect(lines).to be_any { |s| s =~ /Query:/ }
32
+ expect(lines).to be_any { |s| s =~ cell("JobId") }
33
+ expect(lines).to be_any { |s| s =~ cell("PerPage") }
34
+ expect(lines).to be_any { |s| s =~ /Results:/ }
35
+ expect(lines).to be_any { |s| s =~ cell("Email") }
36
+ expect(lines).to be_any { |s| s =~ cell("SuggCorr") }
37
+ end
38
+ end
39
+ end
40
+ end; end; end
@@ -0,0 +1,59 @@
1
+
2
+ module NeverBounce; module CLI; module Script
3
+ describe JobsSearch do
4
+ include_dir_context __dir__
5
+
6
+ def margv(*args)
7
+ ["API_KEY=abc"] + args
8
+ end
9
+
10
+ it_behaves_like "instantiatable"
11
+ it_behaves_like "a script supporting `--help`", signatures: [/nb-jobs-search/, /PAGE/]
12
+
13
+ describe "mode attributes" do
14
+ describe "#job_id" do
15
+ let(:m) { :job_id }
16
+ it "generally works" do
17
+ expect(newo(env: {}).send(m)).to be nil
18
+ expect(newo(env: {"ID" => "abc"}).send(m)).to eq "abc"
19
+ expect(newo(env: {"ID" => "12"}).send(m)).to eq "12"
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#request_curl" do
25
+ it "generally works" do
26
+ r = goodo(argv: margv(
27
+ "ID=abc",
28
+ "PAGE=12",
29
+ "PER_PAGE=34",
30
+ ))
31
+ expect(r.job_id).to eq "abc"
32
+ expect(r.page).to eq 12
33
+ expect(r.per_page).to eq 34
34
+ expect(r.request_curl).to eq ["--request", "GET", "--url", "https://api.neverbounce.com/v4/jobs/search", "--header", "Content-Type: application/json", "--data-binary", "{\"key\":\"abc\",\"job_id\":\"abc\",\"page\":12,\"items_per_page\":34}"]
35
+ end
36
+ end
37
+
38
+ describe "output" do
39
+ it "generally works" do
40
+ r = goodo(argv: margv).tap do |_|
41
+ _.session.server_content_type = "application/json"
42
+ _.session.server_raw = '{"status":"success","total_results":5,"total_pages":1,"query":{"page":1,"items_per_page":1000},"results":[{"id":276816,"job_status":"failed","filename":"","created_at":"2017-07-25 09:04:10","started_at":null,"finished_at":null,"total":{"records":0,"billable":0,"processed":null,"valid":null,"invalid":0,"catchall":null,"disposable":null,"unknown":null,"duplicates":null,"bad_syntax":null},"bounce_estimate":-1,"percent_complete":0},{"id":276760,"job_status":"failed","filename":"","created_at":"2017-07-25 08:31:16","started_at":null,"finished_at":null,"total":{"records":0,"billable":0,"processed":null,"valid":null,"invalid":0,"catchall":null,"disposable":null,"unknown":null,"duplicates":null,"bad_syntax":null},"bounce_estimate":-1,"percent_complete":0},{"id":276743,"job_status":"queued","filename":"","created_at":"2017-07-25 08:06:38","started_at":null,"finished_at":null,"total":{"records":0,"billable":0,"processed":0,"valid":0,"invalid":0,"catchall":0,"disposable":0,"unknown":0,"duplicates":0,"bad_syntax":0},"bounce_estimate":-1,"percent_complete":0},{"id":276736,"job_status":"queued","filename":"","created_at":"2017-07-25 07:54:29","started_at":null,"finished_at":null,"total":{"records":0,"billable":0,"processed":0,"valid":0,"invalid":0,"catchall":0,"disposable":0,"unknown":0,"duplicates":0,"bad_syntax":0},"bounce_estimate":-1,"percent_complete":0},{"id":274226,"job_status":"complete","filename":"Created from Array.csv","created_at":"2017-07-21 17:33:45","started_at":"2017-07-21 17:33:46","finished_at":"2017-07-21 17:33:47","total":{"records":3,"billable":2,"processed":3,"valid":1,"invalid":2,"catchall":0,"disposable":0,"unknown":0,"duplicates":0,"bad_syntax":1},"bounce_estimate":0,"percent_complete":100}],"execution_time":402}'
43
+ end
44
+ expect { r.main }.not_to raise_error
45
+ lines = r.stdout.tap(&:rewind).to_a
46
+ expect(lines).to be_any { |s| s =~ /Response:/ }
47
+ expect(lines).to be_any { |s| s =~ cell("ExecTime") }
48
+ expect(lines).to be_any { |s| s =~ /Query:/ }
49
+ expect(lines).to be_any { |s| s =~ cell("Page") }
50
+ expect(lines).to be_any { |s| s =~ cell("PerPage") }
51
+ expect(lines).to be_any { |s| s =~ /Results:/ }
52
+ expect(lines).to be_any { |s| s =~ cell("ID") }
53
+ expect(lines).to be_any { |s| s =~ cell("JobStatus") }
54
+ expect(lines).to be_any { |s| s =~ cell("Filename") }
55
+ expect(lines).to be_any { |s| s =~ cell("Total") }
56
+ end
57
+ end
58
+ end
59
+ end; end; end
@@ -0,0 +1,45 @@
1
+
2
+ module NeverBounce; module CLI; module Script
3
+ describe JobsStart do
4
+ include_dir_context __dir__
5
+
6
+ def margv(*args)
7
+ ["API_KEY=abc", "ID=12"] + args
8
+ end
9
+
10
+ it_behaves_like "instantiatable"
11
+ it_behaves_like "a script supporting `--help`", signatures: [/nb-jobs-start/, /ID/, /RUN_SAMPLE/]
12
+
13
+ describe "mode attributes" do
14
+ describe "#run_sample" do
15
+ let(:m) { :run_sample }
16
+ it "generally works" do
17
+ expect(newo(env: {}).send(m)).to be nil
18
+ expect(newo(env: {"RUN_SAMPLE" => "y"}).send(m)).to be true
19
+ expect(newo(env: {"RUN_SAMPLE" => "n"}).send(m)).to be false
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#request_curl" do
25
+ it "generally works" do
26
+ r = goodo(argv: margv("RUN_SAMPLE=y"))
27
+ expect(r.request_curl).to eq ["--request", "POST", "--url", "https://api.neverbounce.com/v4/jobs/start", "--header", "Content-Type: application/json", "--data-binary", "{\"job_id\":\"12\",\"key\":\"abc\",\"run_sample\":true}"]
28
+ end
29
+ end
30
+
31
+ describe "output" do
32
+ it "generally works" do
33
+ r = goodo(argv: margv).tap do |_|
34
+ _.session.server_content_type = "application/json"
35
+ _.session.server_raw = '{"status":"success","queue_id":"NB-PQ-598B5ED572898","execution_time":25}'
36
+ end
37
+ expect { r.main }.not_to raise_error
38
+ lines = r.stdout.tap(&:rewind).to_a
39
+ expect(lines).to be_any { |s| s =~ /Response:/ }
40
+ expect(lines).to be_any { |s| s =~ cell("QueueId") }
41
+ expect(lines).to be_any { |s| s =~ cell("ExecTime") }
42
+ end
43
+ end
44
+ end
45
+ end; end; end
@@ -0,0 +1,37 @@
1
+
2
+ module NeverBounce; module CLI; module Script
3
+ describe JobsStatus do
4
+ include_dir_context __dir__
5
+
6
+ def margv(*args)
7
+ ["API_KEY=abc", "ID=12"] + args
8
+ end
9
+
10
+ it_behaves_like "instantiatable"
11
+ it_behaves_like "a script supporting `--help`", signatures: [/nb-jobs-status/]
12
+
13
+ describe "#request_curl" do
14
+ it "generally works" do
15
+ r = goodo(argv: margv)
16
+ expect(r.request_curl).to eq ["--request", "GET", "--url", "https://api.neverbounce.com/v4/jobs/status", "--header", "Content-Type: application/json", "--data-binary", "{\"job_id\":\"12\",\"key\":\"abc\"}"]
17
+ end
18
+ end
19
+
20
+ describe "output" do
21
+ it "generally works" do
22
+ r = goodo(argv: margv).tap do |_|
23
+ _.session.server_content_type = "application/json"
24
+ _.session.server_raw = '{"status":"success","id":274226,"job_status":"complete","filename":"Created from Array.csv","created_at":"2017-07-21 17:33:45","started_at":"2017-07-21 17:33:46","finished_at":"2017-07-21 17:33:47","total":{"records":3,"billable":2,"processed":3,"valid":1,"invalid":2,"catchall":0,"disposable":0,"unknown":0,"duplicates":0,"bad_syntax":1},"bounce_estimate":0,"percent_complete":100,"execution_time":7}'
25
+ end
26
+ expect { r.main }.not_to raise_error
27
+ lines = r.stdout.tap(&:rewind).to_a
28
+ expect(lines).to be_any { |s| s =~ /^Response:$/ }
29
+ expect(lines).to be_any { |s| s =~ cell("ID") }
30
+ expect(lines).to be_any { |s| s =~ cell("ExecTime") }
31
+ expect(lines).to be_any { |s| s =~ /^Total:$/ }
32
+ expect(lines).to be_any { |s| s =~ cell("BadSyntax") }
33
+ expect(lines).to be_any { |s| s =~ cell("Valid") }
34
+ end
35
+ end
36
+ end
37
+ end; end; end
@@ -0,0 +1,6 @@
1
+
2
+ describe NeverBounce::CLI::Script::Manifest do
3
+ include_dir_context __dir__
4
+
5
+ it_behaves_like "instantiatable"
6
+ end
@@ -0,0 +1,93 @@
1
+
2
+ describe NeverBounce::CLI::Script::Meaningful do
3
+ include_dir_context __dir__
4
+
5
+ it_behaves_like "instantiatable"
6
+
7
+ describe "command-line options" do
8
+ it "generally works" do
9
+ r = goodo(
10
+ argv: ["A=1", "B=2 3", "C== hey\nthere ="],
11
+ env: {},
12
+ )
13
+ expect { r.options }.not_to raise_error
14
+ expect(r.env).to eq({"A" => "1", "B" => "2 3", "C" => "= hey\nthere ="})
15
+ end
16
+ end
17
+
18
+ describe "successor class" do
19
+ # Generic successor class.
20
+ # Hack: We define it in both scopes to be able to use shared examples.
21
+ the_klass = Class.new(described_class) do
22
+ envar "AA", "No examples"
23
+ envar "AB", "Some examples", ["a", "b"]
24
+ envar "AC", "Examples with a default", ["a", {default: "B"}, "c"]
25
+ envar "AD", "Numeric examples with a default", [1, default: 10]
26
+ envar "BA*", "Mandatory. No examples"
27
+ envar "BB*", "Mandatory. Some examples", ["a", "b"]
28
+ envar "CAaaaaaa", "Longer name"
29
+
30
+ def manifest
31
+ @manifest ||= Class.new do
32
+ def cmdline
33
+ "[some_options]"
34
+ end
35
+
36
+ def function
37
+ "some function"
38
+ end
39
+
40
+ def name
41
+ "some-name"
42
+ end
43
+ end.new
44
+ end
45
+
46
+ def slim_main
47
+ stdout.puts "I'm slim_main"
48
+ 12
49
+ end
50
+ end
51
+
52
+ let(:klass) do
53
+ # Copy local scope variable to example scope.
54
+ the_klass
55
+ end
56
+
57
+ def newo(attrs = {})
58
+ klass.new(attrs)
59
+ end
60
+
61
+ it_behaves_like "a script supporting `--help`", klass: the_klass, signatures: [/some-name/, /some_options/]
62
+
63
+ describe "usage text" do
64
+ describe "#banner_text" do
65
+ it "generally works" do
66
+ expect(newo.banner_text).to eq "some-name - some function"
67
+ end
68
+ end
69
+
70
+ describe "#envar_text" do
71
+ it "generally works" do
72
+ expect(newo.envar_text).to eq "* BA - Mandatory. No examples\n* BB - Mandatory. Some examples (\"a\", \"b\")\n- AA - No examples\n- AB - Some examples (\"a\", \"b\")\n- AC - Examples with a default (\"a\", [\"B\"], \"c\")\n- AD - Numeric examples with a default (1, [10])\n- CAaaaaaa - Longer name"
73
+ end
74
+ end
75
+
76
+ describe "#help_text" do
77
+ it "generally works" do
78
+ r = newo
79
+ expect(r.help_text).to match /\bsome-name\b/
80
+ expect(r.help_text).to match /\bUSAGE:\s/
81
+ expect(r.help_text).to match /\bEnvironment variables:\s/
82
+ end
83
+ end
84
+ end # describe "usage text"
85
+
86
+ it "generally works" do
87
+ r = newo(argv: [], env: {}, stdout: StringIO.new)
88
+ expect(r.main).to eq 12
89
+ lines = r.stdout.tap(&:rewind).to_a
90
+ expect(lines).to eq ["I'm slim_main\n"]
91
+ end
92
+ end # successor class
93
+ end