Class: Typingpool::Test
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- Typingpool::Test
- Defined in:
- lib/typingpool/test.rb,
lib/typingpool/test/script.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Script
Class Attribute Summary collapse
-
.live ⇒ Object
Returns the value of attribute live.
-
.record ⇒ Object
Returns the value of attribute record.
Class Method Summary collapse
Instance Method Summary collapse
- #add_goodbye_message(msg) ⇒ Object
- #amazon_credentials?(config = self.config) ⇒ Boolean
- #audio_dir ⇒ Object
- #broken_url_eventually?(url, max_seconds = 10, min_tries = 2, max_redirects = 6) ⇒ Boolean
- #cleared_vcr_fixture_path_for(fixture_name) ⇒ Object
- #config ⇒ Object
- #delete_vcr_fixture(fixture_name) ⇒ Object
- #dummy_config(number = 1) ⇒ Object
- #fetch_url(*args) ⇒ Object
- #fixtures_dir ⇒ Object
- #in_temp_dir ⇒ Object
- #project_default ⇒ Object
- #s3_credentials?(config) ⇒ Boolean
- #sftp_credentials?(config) ⇒ Boolean
- #skip_during_vcr_playback(skipping_what = '') ⇒ Object
- #skip_if_no_amazon_credentials(skipping_what = '', config = self.config) ⇒ Object
- #skip_if_no_s3_credentials(skipping_what = '', config = self.config) ⇒ Object
- #skip_if_no_sftp_credentials(skipping_what = '', config = self.config) ⇒ Object
- #skip_if_no_upload_credentials(skipping_what = '', config = self.config) ⇒ Object
- #skip_with_message(reason, skipping_what = '') ⇒ Object
- #vcr_dir ⇒ Object
- #with_vcr(fixture_name, config, opts = {}) ⇒ Object
- #working_url?(*args) ⇒ Boolean
- #working_url_eventually?(url, max_seconds = 10, min_tries = 2, max_redirects = 6) ⇒ Boolean
- #works_eventually?(max_seconds = 10, min_tries = 2) ⇒ Boolean
Class Attribute Details
.live ⇒ Object
Returns the value of attribute live.
7 8 9 |
# File 'lib/typingpool/test.rb', line 7 def live @live end |
.record ⇒ Object
Returns the value of attribute record.
8 9 10 |
# File 'lib/typingpool/test.rb', line 8 def record @record end |
Class Method Details
.app_dir ⇒ Object
10 11 12 |
# File 'lib/typingpool/test.rb', line 10 def app_dir Utility.app_dir end |
Instance Method Details
#add_goodbye_message(msg) ⇒ Object
113 114 115 116 117 |
# File 'lib/typingpool/test.rb', line 113 def (msg) at_exit do STDERR.puts msg end end |
#amazon_credentials?(config = self.config) ⇒ Boolean
65 66 67 |
# File 'lib/typingpool/test.rb', line 65 def amazon_credentials?(config=self.config) config.amazon && config.amazon.key && config.amazon.secret end |
#audio_dir ⇒ Object
23 24 25 |
# File 'lib/typingpool/test.rb', line 23 def audio_dir File.join(fixtures_dir, 'audio') end |
#broken_url_eventually?(url, max_seconds = 10, min_tries = 2, max_redirects = 6) ⇒ Boolean
164 165 166 167 168 |
# File 'lib/typingpool/test.rb', line 164 def broken_url_eventually?(url, max_seconds=10, min_tries=2, max_redirects=6) works_eventually?(max_seconds, min_tries) do not(working_url?(url, max_redirects)) end end |
#cleared_vcr_fixture_path_for(fixture_name) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/typingpool/test.rb', line 36 def cleared_vcr_fixture_path_for(fixture_name) if Typingpool::Test.record delete_vcr_fixture(fixture_name) end if (Typingpool::Test.record || not(Typingpool::Test.live)) File.join(vcr_dir, fixture_name) end end |
#config ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/typingpool/test.rb', line 57 def config if File.exist?(File.(Config.default_file)) Config.file else Config.from_bundled_template end end |
#delete_vcr_fixture(fixture_name) ⇒ Object
31 32 33 34 |
# File 'lib/typingpool/test.rb', line 31 def delete_vcr_fixture(fixture_name) fixture_path = File.join(vcr_dir, [fixture_name, '.yml'].join) File.delete(fixture_path) if File.exist? fixture_path end |
#dummy_config(number = 1) ⇒ Object
119 120 121 |
# File 'lib/typingpool/test.rb', line 119 def dummy_config(number=1) Typingpool::Config.file(File.join(fixtures_dir, "config-#{number}")) end |
#fetch_url(*args) ⇒ Object
170 171 172 |
# File 'lib/typingpool/test.rb', line 170 def fetch_url(*args) Typingpool::Utility.fetch_url(*args) end |
#fixtures_dir ⇒ Object
19 20 21 |
# File 'lib/typingpool/test.rb', line 19 def fixtures_dir File.join(Utility.lib_dir, 'test', 'fixtures') end |
#in_temp_dir ⇒ Object
136 137 138 |
# File 'lib/typingpool/test.rb', line 136 def in_temp_dir Typingpool::Utility.in_temp_dir{|dir| yield(dir) } end |
#project_default ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/typingpool/test.rb', line 124 def project_default Hash[ :config_filename => '.config', :subtitle => "Typingpool's test interview transcription", :title => "Typingpool's Test & Interview", :chunks => '0:22', :unusual => ['Hack Day', 'Sunnyvale', 'Chad D'], :voice => ['Ryan', 'Havi, hacker'], ] end |
#s3_credentials?(config) ⇒ Boolean
81 82 83 |
# File 'lib/typingpool/test.rb', line 81 def s3_credentials?(config) amazon_credentials?(config) && config.amazon.bucket end |
#sftp_credentials?(config) ⇒ Boolean
93 94 95 |
# File 'lib/typingpool/test.rb', line 93 def sftp_credentials?(config) config.sftp && config.sftp.user && config.sftp.host && config.sftp.url end |
#skip_during_vcr_playback(skipping_what = '') ⇒ Object
103 104 105 |
# File 'lib/typingpool/test.rb', line 103 def skip_during_vcr_playback(skipping_what='') ("Runs only with --live or --record option", skipping_what) unless (Typingpool::Test.live || Typingpool::Test.record) end |
#skip_if_no_amazon_credentials(skipping_what = '', config = self.config) ⇒ Object
75 76 77 78 79 |
# File 'lib/typingpool/test.rb', line 75 def skip_if_no_amazon_credentials(skipping_what='', config=self.config) if not (amazon_credentials?(config)) ('Missing or incomplete Amazon credentials', skipping_what) end end |
#skip_if_no_s3_credentials(skipping_what = '', config = self.config) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/typingpool/test.rb', line 85 def skip_if_no_s3_credentials(skipping_what='', config=self.config) if not (skip_if_no_amazon_credentials(skipping_what, config)) if not(s3_credentials?(config)) ('No Amazon S3 credentials', skipping_what) end #if not(s3_credentials?...) end #if not(skip_if_no_amazon_credentials...) end |
#skip_if_no_sftp_credentials(skipping_what = '', config = self.config) ⇒ Object
97 98 99 100 101 |
# File 'lib/typingpool/test.rb', line 97 def skip_if_no_sftp_credentials(skipping_what='', config=self.config) if not(sftp_credentials?(config)) ('No SFTP credentials', skipping_what) end #if not(sftp_credentials?... end |
#skip_if_no_upload_credentials(skipping_what = '', config = self.config) ⇒ Object
107 108 109 110 111 |
# File 'lib/typingpool/test.rb', line 107 def skip_if_no_upload_credentials(skipping_what='', config=self.config) if not(s3_credentials?(config) || sftp_credentials?(config)) ("No S3 or SFTP credentials in config", skipping_what) end #if not(s3_credentials?... end |
#skip_with_message(reason, skipping_what = '') ⇒ Object
69 70 71 72 73 |
# File 'lib/typingpool/test.rb', line 69 def (reason, skipping_what='') skipping_what = " #{skipping_what}" unless skipping_what.empty? skip ("Skipping#{skipping_what}: #{reason}") true end |
#vcr_dir ⇒ Object
27 28 29 |
# File 'lib/typingpool/test.rb', line 27 def vcr_dir File.join(fixtures_dir, 'vcr') end |
#with_vcr(fixture_name, config, opts = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/typingpool/test.rb', line 45 def with_vcr(fixture_name, config, opts={}) if fixture = cleared_vcr_fixture_path_for(fixture_name) read_only = not(Typingpool::Test.record) Typingpool::App.vcr_load(fixture, config, read_only, opts) end begin yield ensure Typingpool::App.vcr_stop end end |
#working_url?(*args) ⇒ Boolean
140 141 142 |
# File 'lib/typingpool/test.rb', line 140 def working_url?(*args) Typingpool::Utility.working_url?(*args) end |
#working_url_eventually?(url, max_seconds = 10, min_tries = 2, max_redirects = 6) ⇒ Boolean
158 159 160 161 162 |
# File 'lib/typingpool/test.rb', line 158 def working_url_eventually?(url, max_seconds=10, min_tries=2, max_redirects=6) works_eventually?(max_seconds, min_tries) do working_url?(url, max_redirects) end end |
#works_eventually?(max_seconds = 10, min_tries = 2) ⇒ Boolean
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/typingpool/test.rb', line 145 def works_eventually?(max_seconds=10, min_tries=2) start = Time.now.to_i tries = 0 wait = 0 until ((tries >= min_tries) && ((Time.now.to_i + wait - start) >= max_seconds)) do sleep wait return true if yield wait = wait > 0 ? wait * 2 : 1 tries += 1 end false end |