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.
6 7 8 |
# File 'lib/typingpool/test.rb', line 6 def live @live end |
.record ⇒ Object
Returns the value of attribute record.
7 8 9 |
# File 'lib/typingpool/test.rb', line 7 def record @record end |
Class Method Details
.app_dir ⇒ Object
9 10 11 |
# File 'lib/typingpool/test.rb', line 9 def app_dir File.dirname(File.dirname(File.dirname(__FILE__))) end |
Instance Method Details
#add_goodbye_message(msg) ⇒ Object
112 113 114 115 116 |
# File 'lib/typingpool/test.rb', line 112 def (msg) at_exit do STDERR.puts msg end end |
#amazon_credentials?(config = self.config) ⇒ Boolean
64 65 66 |
# File 'lib/typingpool/test.rb', line 64 def amazon_credentials?(config=self.config) config.amazon && config.amazon.key && config.amazon.secret end |
#audio_dir ⇒ Object
22 23 24 |
# File 'lib/typingpool/test.rb', line 22 def audio_dir File.join(fixtures_dir, 'audio') end |
#broken_url_eventually?(url, max_seconds = 10, min_tries = 2, max_redirects = 6) ⇒ Boolean
163 164 165 166 167 |
# File 'lib/typingpool/test.rb', line 163 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
35 36 37 38 39 40 41 42 |
# File 'lib/typingpool/test.rb', line 35 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
56 57 58 59 60 61 62 |
# File 'lib/typingpool/test.rb', line 56 def config if File.exists?(File.(Config.default_file)) Config.file else Config.from_bundled_template end end |
#delete_vcr_fixture(fixture_name) ⇒ Object
30 31 32 33 |
# File 'lib/typingpool/test.rb', line 30 def delete_vcr_fixture(fixture_name) fixture_path = File.join(vcr_dir, [fixture_name, '.yml'].join) File.delete(fixture_path) if File.exists? fixture_path end |
#dummy_config(number = 1) ⇒ Object
118 119 120 |
# File 'lib/typingpool/test.rb', line 118 def dummy_config(number=1) Typingpool::Config.file(File.join(fixtures_dir, "config-#{number}")) end |
#fetch_url(*args) ⇒ Object
169 170 171 |
# File 'lib/typingpool/test.rb', line 169 def fetch_url(*args) Typingpool::Utility.fetch_url(*args) end |
#fixtures_dir ⇒ Object
18 19 20 |
# File 'lib/typingpool/test.rb', line 18 def fixtures_dir File.join(Utility.lib_dir, 'test', 'fixtures') end |
#in_temp_dir ⇒ Object
135 136 137 |
# File 'lib/typingpool/test.rb', line 135 def in_temp_dir Typingpool::Utility.in_temp_dir{|dir| yield(dir) } end |
#project_default ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/typingpool/test.rb', line 123 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
80 81 82 |
# File 'lib/typingpool/test.rb', line 80 def s3_credentials?(config) amazon_credentials?(config) && config.amazon.bucket end |
#sftp_credentials?(config) ⇒ Boolean
92 93 94 |
# File 'lib/typingpool/test.rb', line 92 def sftp_credentials?(config) config.sftp && config.sftp.user && config.sftp.host && config.sftp.url end |
#skip_during_vcr_playback(skipping_what = '') ⇒ Object
102 103 104 |
# File 'lib/typingpool/test.rb', line 102 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
74 75 76 77 78 |
# File 'lib/typingpool/test.rb', line 74 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
84 85 86 87 88 89 90 |
# File 'lib/typingpool/test.rb', line 84 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
96 97 98 99 100 |
# File 'lib/typingpool/test.rb', line 96 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
106 107 108 109 110 |
# File 'lib/typingpool/test.rb', line 106 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
68 69 70 71 72 |
# File 'lib/typingpool/test.rb', line 68 def (reason, skipping_what='') skipping_what = " #{skipping_what}" unless skipping_what.empty? skip ("Skipping#{skipping_what}: #{reason}") true end |
#vcr_dir ⇒ Object
26 27 28 |
# File 'lib/typingpool/test.rb', line 26 def vcr_dir File.join(fixtures_dir, 'vcr') end |
#with_vcr(fixture_name, config, opts = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/typingpool/test.rb', line 44 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
139 140 141 |
# File 'lib/typingpool/test.rb', line 139 def working_url?(*args) Typingpool::Utility.working_url?(*args) end |
#working_url_eventually?(url, max_seconds = 10, min_tries = 2, max_redirects = 6) ⇒ Boolean
157 158 159 160 161 |
# File 'lib/typingpool/test.rb', line 157 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
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/typingpool/test.rb', line 144 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 |