This repository has been archived by the owner on Apr 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move config_var from Bugzilla and Quote plugin into Plugin class
The config_var tool has been handy for processing configuration parameters for a plugin. It seems generic enough to roll into the Plugin class. Move the config_var class method and the initialize block into the Plugin class. Be sure to call "super" from the subclass's initialize method. Move the applicable examples into a separate plugin_spec.
- Loading branch information
Showing
5 changed files
with
63 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'spec' | ||
BOT_ROOT = File.join(File.dirname(__FILE__), '..') | ||
BOT_ENVIRONMENT = 'test' | ||
|
||
require File.join(File.dirname(__FILE__), '../lib/bot.rb') | ||
bot = CampfireBot::Bot.instance | ||
|
||
describe "config_var method" do | ||
class ExamplePlugin < CampfireBot::Plugin | ||
config_var :foo, "default foo" | ||
end | ||
|
||
def setup_plugin(klass, config={}) | ||
@bot = CampfireBot::Bot.instance | ||
@bot.stub!(:config).and_return({'nickname' => 'Bot'}.merge(config)) | ||
@plugin = klass.new | ||
CampfireBot::Plugin.registered_plugins[klass.to_s] = @plugin | ||
end | ||
|
||
it "should setup default bug_url value" do | ||
setup_plugin ExamplePlugin | ||
@plugin.foo.should == "default foo" | ||
end | ||
|
||
it "should allow override of parameter via configuration" do | ||
setup_plugin ExamplePlugin, 'example_plugin_foo' => 'bar' | ||
@plugin.foo.should == "bar" | ||
end | ||
|
||
it "should keep defaults for two classes separate" do | ||
class ExamplePlugin2 < CampfireBot::Plugin | ||
config_var :bar, "default bar" | ||
end | ||
setup_plugin ExamplePlugin | ||
plugin = @plugin | ||
setup_plugin ExamplePlugin2 | ||
plugin.instance_variable_get(:@foo).should == "default foo" | ||
@plugin.instance_variable_get(:@bar).should == "default bar" | ||
# Used to fail with value "default bar" | ||
plugin.instance_variable_get(:@bar).should == nil | ||
@plugin.instance_variable_get(:@foo).should == nil | ||
end | ||
end |