Hi,
This patchset allow you to run Cucumber features on EC2 for free ;-)
How ?
Mocking. We have some 'mock' already, but unfortunatelly it work *only* for EC2 and was written for this provider.
After applying this patch, you will see that now mocking is done in nicer and more 'abstract' way and basically it's driver independent.
After brief look to 'base_driver/mock_driver.rb' we can spot block of code which did that job:
def self.wrap_methods(c) c.class_eval do cached_methods.each do |m| alias_method "original_#{m}".to_sym, m.to_sym define_method m.to_sym do |*args| args = args.first if args.size.eql?(1) and args.first.class.eql?(Hash) output = deserialize_data(m, args) unless output output = method("original_#{m}".to_sym).to_proc[args] serialize_data(m, output , args) unless output end return output end end end end
Explanation:
If you include this module into some class, it wraps methods returned from 'cached_methods' class method. Then it takes method arguments and method name and lookup for serialized data. If there are no serialized data to use, it calls original method and serialize output into Base64 file. When you use this method again, it doesn't call original method but use 'cached' data from mock instead.
There are two nice things:
1. Checksum is created from arguments, so you can call one method with different arguments and this is 'serialized' again and again...
2. For different scenarios you can 'prefix' mock files. (@create-instance, @destroy-instance...)
Some 'sample' data from my EC2 account are included. You can create your own data. All you need to do is write your API credentials into tests/support/ec2/env.rb. Then just run 'rake cucumber' and all output data will be recorded. When you then run this task again, it'll use recorded data instead of connecting to EC2.
Howto start:
1. cd core/tests 2. export API_DRIVER="ec2" 3. rake cucumber
There are still some issues with 'reboot' and 'create' instance, but I hope I'll fix this stuff very soon.
-- Michal