Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding test for creating code package

  • Loading branch information...
commit 558c81dc78f080b78d034147955073d5acae6db8 1 parent 7b9ed95
@romand romand authored
View
2  lib/iron_worker_ng/code/base.rb
@@ -51,6 +51,8 @@ def initialize(*args, &block)
exec = args[0][:exec] || args[0]['exec'] || args[0][:worker] || args[0]['worker']
merge_exec(exec) unless exec.nil?
+ else
+ raise "Wrong arguments"
end
unless block.nil?
View
16 test/helpers.rb
@@ -3,8 +3,8 @@
require './lib/iron_worker_ng.rb'
-def code_bundle(name,&block)
- code = IronWorkerNG::Code::Ruby.new(name)
+def code_bundle(*args,&block)
+ code = IronWorkerNG::Code::Ruby.new(*args)
class << code
def worker_code(str)
@@ -19,7 +19,7 @@ def worker_code(str)
end
end
- code.instance_eval(&block)
+ code.instance_eval(&block) if block_given?
code
end
@@ -44,3 +44,13 @@ def setup
:project_id => project_id )
end
end
+
+module IronWorkerNG
+ module Code
+ class Base
+ def exec_path
+ exec = @features.find{|f| f.is_a? IronWorkerNG::Feature::Ruby::MergeExec::Feature } and exec.path
+ end
+ end
+ end
+end
View
34 test/test_code_create.rb
@@ -0,0 +1,34 @@
+require 'helpers'
+
+class CodeCreateTest < IWNGTest
+
+ def test_wrong_args
+ assert_raises RuntimeError do
+ code_bundle('Hello', 'hello.rb')
+ end
+
+ assert_raises RuntimeError do
+ code_bundle('hello.rb', :name => 'Hello')
+ end
+
+ assert_raises RuntimeError do
+ client.codes_create(code_bundle(:worker_path => 'hello.rb',
+ :name => 'Hello'))
+ end
+ end
+
+ def test_create
+ code = code_bundle('test/hello.rb')
+ assert_equal File.expand_path('test/hello.rb'), code.exec_path
+ assert_equal 'Hello', code.name
+
+ code = code_bundle('asdfasdf')
+ assert_equal nil, code.exec_path
+ assert_equal 'asdfasdf', code.name
+
+ code = code_bundle(:exec => 'test/hello.rb', :name => 'dfdfd')
+ assert_equal File.expand_path('test/hello.rb'), code.exec_path
+ assert_equal 'dfdfd', code.name
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.