Class: FakeAPI::TestRun
- Inherits:
-
Object
- Object
- FakeAPI::TestRun
- Defined in:
- lib/fakeapi/test_run.rb
Constant Summary collapse
- NET_HTTP =
::Net::HTTP
Instance Method Summary collapse
-
#initialize(api, method_name, run_block) ⇒ TestRun
constructor
A new instance of TestRun.
- #run ⇒ Object
- #run_with_artifice ⇒ Object
- #run_with_vcr ⇒ Object
Constructor Details
#initialize(api, method_name, run_block) ⇒ TestRun
Returns a new instance of TestRun.
14 15 16 17 18 |
# File 'lib/fakeapi/test_run.rb', line 14 def initialize(api, method_name, run_block) @api = api @method_name = method_name @run_block = run_block end |
Instance Method Details
#run ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/fakeapi/test_run.rb', line 20 def run begin run_with_artifice rescue => ex p ex run_with_vcr end end |
#run_with_artifice ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/fakeapi/test_run.rb', line 29 def run_with_artifice ret = nil Artifice.activate_with @api do ret = @run_block.call end ret end |
#run_with_vcr ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fakeapi/test_run.rb', line 37 def run_with_vcr if ::Net::HTTP != NET_HTTP ::Net.class_eval do remove_const(:HTTP) const_set(:HTTP, NET_HTTP) end end VCR.use_cassette(@method_name, &@run_block) color = Term::ANSIColor puts puts color.green + 'Use generated code:' + color.clear puts puts color.yellow + FakeAPI::Generator.generate(@method_name) + color.clear raise NotImplementedError end |