botfly 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -1,6 +1,7 @@
1
1
  Botfly Todo List (by priority)
2
2
  ==============================
3
3
  * Have Bot.new and Bot#run instead of just #login that always runs
4
+ * Write cucumber integration testes
4
5
  * Replace CommonBlockAcceptor responder chain array with ResponderChain object
5
6
  ** Spec & create ResponderChain class
6
7
  ** Have responder chain stop call first responder ONLY after reaching a match
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
data/botfly.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{botfly}
8
- s.version = "0.3.5"
8
+ s.version = "0.3.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Neufeld"]
@@ -34,12 +34,26 @@ module Botfly
34
34
  def initialize(obj); @obj = obj; end
35
35
 
36
36
  def method_missing(name,&block)
37
+ @type = name
37
38
  Botfly.logger.info("#{@obj.to_debug_s}: Bot#on")
38
- klass = Botfly.const_get(@obj.class_prefix + name.to_s.split('_').map(&:capitalize).join + "Responder")
39
+
39
40
  (@obj.responders[name] ||= []) << responder = klass.new(@obj, &block)
40
41
  Botfly.logger.info("#{@obj.to_debug_s}: #{@obj.class_prefix}#{name.to_s.capitalize}Responder added to responder chain")
41
42
  return responder
42
43
  end
44
+
45
+ private
46
+ def klass
47
+ begin
48
+ klass = Botfly.const_get(@obj.class_prefix + @type.to_s.split('_').map(&:capitalize).join + "Responder")
49
+ rescue
50
+ if @obj.class_prefix.empty?
51
+ klass = Responder
52
+ else
53
+ klass = Botfly.const_get(@obj.class_prefix+"Responder")
54
+ end
55
+ end
56
+ end
43
57
  end
44
58
 
45
59
  def class_prefix; ''; end
@@ -52,7 +52,7 @@ describe CommonBlockAcceptor do
52
52
  class FooBarResponder; def initialize(baz);end; end
53
53
  end
54
54
 
55
- it "should instanciate responder based on name" do
55
+ it "should instanciate specialized responder based on name if class exists" do
56
56
  FooResponder.should_receive(:new)
57
57
  on.foo
58
58
  end
@@ -65,7 +65,7 @@ describe CommonBlockAcceptor do
65
65
  it "should add class prefix to front of responder class" do
66
66
  acceptor.stub(:class_prefix).and_return('Foo')
67
67
  Botfly.should_receive(:const_get).with('FooBarResponder').and_return(FooBarResponder)
68
- on.bar
68
+ on.bar.should be_a_kind_of FooBarResponder
69
69
  end
70
70
 
71
71
  it "should add responder to object's responder chain hash" do
@@ -80,6 +80,17 @@ describe CommonBlockAcceptor do
80
80
  FooResponder.stub(:new).and_return(:foo_instance)
81
81
  on.foo.should be :foo_instance
82
82
  end
83
+
84
+ it "should default to Responder for basic responder" do
85
+ Responder.stub(:new).and_return(:plain)
86
+ on.baz.should be :plain
87
+ end
88
+
89
+ it "should still add class prefix even if special responder not found" do
90
+ acceptor.stub(:class_prefix).and_return('Foo')
91
+ FooResponder.stub(:new).and_return(:plain)
92
+ on.baz.should be :plain
93
+ end
83
94
  end
84
95
  end
85
96
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 5
9
- version: 0.3.5
8
+ - 6
9
+ version: 0.3.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Neufeld