| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper" |
| 8 |
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_plugin_manager' |
| 9 |
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_expect' |
| 10 |
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_ignore' |
| 11 |
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_cexception' |
| 12 |
|
| 13 |
describe CMockPluginManager, "Verify CMockPluginManager Module" do |
| 14 |
|
| 15 |
before do |
| 16 |
create_mocks :utils, :pluginA, :pluginB |
| 17 |
@config = create_stub( |
| 18 |
:respond_to => true, |
| 19 |
:when_ptr => :compare_data, |
| 20 |
:enforce_strict_ordering => false, |
| 21 |
:ignore => :args_and_calls, |
| 22 |
:exclude_setjmp_h => false |
| 23 |
) |
| 24 |
|
| 25 |
def @config.plugins |
| 26 |
if instance_variable_defined?(:@plugins) |
| 27 |
@plugins || [] |
| 28 |
else |
| 29 |
[] |
| 30 |
end |
| 31 |
end |
| 32 |
|
| 33 |
def @config.plugins=(val) |
| 34 |
@plugins = val |
| 35 |
end |
| 36 |
end |
| 37 |
|
| 38 |
after do |
| 39 |
end |
| 40 |
|
| 41 |
it "return all plugins by default" do |
| 42 |
@config.plugins = ['cexception','ignore'] |
| 43 |
@utils.expect :helpers, {} |
| 44 |
|
| 45 |
@cmock_plugins = CMockPluginManager.new(@config, @utils) |
| 46 |
|
| 47 |
test_plugins = @cmock_plugins.plugins |
| 48 |
contained = { :expect => false, :ignore => false, :cexception => false } |
| 49 |
test_plugins.each do |plugin| |
| 50 |
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect) |
| 51 |
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore) |
| 52 |
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception) |
| 53 |
end |
| 54 |
assert_equal(true, contained[:expect]) |
| 55 |
assert_equal(true, contained[:ignore]) |
| 56 |
assert_equal(true, contained[:cexception]) |
| 57 |
end |
| 58 |
|
| 59 |
it "return restricted plugins based on config" do |
| 60 |
@utils.expect :helpers, {} |
| 61 |
|
| 62 |
@cmock_plugins = CMockPluginManager.new(@config, @utils) |
| 63 |
|
| 64 |
test_plugins = @cmock_plugins.plugins |
| 65 |
contained = { :expect => false, :ignore => false, :cexception => false } |
| 66 |
test_plugins.each do |plugin| |
| 67 |
contained[:expect] = true if plugin.instance_of?(CMockGeneratorPluginExpect) |
| 68 |
contained[:ignore] = true if plugin.instance_of?(CMockGeneratorPluginIgnore) |
| 69 |
contained[:cexception] = true if plugin.instance_of?(CMockGeneratorPluginCexception) |
| 70 |
end |
| 71 |
assert_equal(true, contained[:expect]) |
| 72 |
assert_equal(false,contained[:ignore]) |
| 73 |
assert_equal(false,contained[:cexception]) |
| 74 |
end |
| 75 |
|
| 76 |
it "run a desired method over each plugin requested and return the results" do |
| 77 |
@utils.expect :helpers, {} |
| 78 |
@cmock_plugins = CMockPluginManager.new(@config, @utils) |
| 79 |
|
| 80 |
@pluginA = create_stub(:test_method => ["This Is An Awesome Test-"]) |
| 81 |
@pluginB = create_stub(:test_method => ["And This is Part 2-","Of An Awesome Test"]) |
| 82 |
@cmock_plugins.plugins = [@pluginA, @pluginB] |
| 83 |
|
| 84 |
expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test" |
| 85 |
output = @cmock_plugins.run(:test_method) |
| 86 |
assert_equal(expected, output) |
| 87 |
end |
| 88 |
|
| 89 |
it "run a desired method and arg list over each plugin requested and return the results" do |
| 90 |
@utils.expect :helpers, {} |
| 91 |
@cmock_plugins = CMockPluginManager.new(@config, @utils) |
| 92 |
|
| 93 |
@pluginA = create_stub(:test_method => ["This Is An Awesome Test-"]) |
| 94 |
@pluginB = create_stub(:test_method => ["And This is Part 2-","Of An Awesome Test"]) |
| 95 |
@cmock_plugins.plugins = [@pluginA, @pluginB] |
| 96 |
|
| 97 |
expected = "This Is An Awesome Test-And This is Part 2-Of An Awesome Test" |
| 98 |
output = @cmock_plugins.run(:test_method, "chickenpotpie") |
| 99 |
assert_equal(expected, output) |
| 100 |
end |
| 101 |
end |