mole 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mole/module.rb CHANGED
@@ -154,6 +154,11 @@ class Module
154
154
  # ===========================================================================
155
155
  private
156
156
 
157
+ # Strip out all invalid punctuation
158
+ def clean_method_name( method )
159
+ return method.to_s.sub(/([?!=])$/, ''), $1
160
+ end
161
+
157
162
  # Clear MOle state for this class # Used for testing only
158
163
  def mole_clear!
159
164
  @before_mole_filters = nil
@@ -208,8 +213,9 @@ class Module
208
213
  # between = find_public_class_method( method )
209
214
  raise "Unable to find moled feature `#{method}" unless(between)
210
215
  end
216
+ method_name, punctuation = clean_method_name( method )
211
217
  code = <<-code
212
- def #{method}_with_mole (*a, &b)
218
+ def #{method_name}_with_mole#{punctuation} (*a, &b)
213
219
  key = '#{method}'
214
220
  klass = self.class
215
221
  between = klass.wrapped[key]
@@ -7,6 +7,12 @@ module Mole
7
7
  class Frameworks
8
8
  class << self
9
9
 
10
+ # compiles request parameters in a flat list.
11
+ def flatten_params( context )
12
+ return nil unless context.respond_to? :params
13
+ context.params.keys.sort{ |a,b| a.to_s <=> b.to_s }.collect{ |k| "#{k} => #{context.params[k]}" }.join( ", ")
14
+ end
15
+
10
16
  # find moleable features for a given class
11
17
  def features_for( controller_class )
12
18
  # Try rails first
data/lib/mole/version.rb CHANGED
@@ -2,7 +2,7 @@ module Mole
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 6
5
+ TINY = 7
6
6
 
7
7
  # Returns the version string for the library.
8
8
  #
data/lib/mole.rb CHANGED
@@ -203,7 +203,8 @@ unless defined? Mole
203
203
  def self.find_controller_classes( dir )
204
204
  classes = []
205
205
  search_me = ::File.expand_path( ::File.join(dir, '*.rb'))
206
- Dir.glob(search_me).sort.each {|rb| classes << camelize( File.basename( rb, ".rb") ) }
206
+ # BOZO !! This kind of sucks - need to exclude application controller for rails otherwise class loading error ??
207
+ Dir.glob(search_me).sort.each {|rb| classes << camelize( File.basename( rb, ".rb") ) unless File.basename( rb, ".rb") == "application" }
207
208
  classes
208
209
  end
209
210
 
@@ -8,7 +8,7 @@
8
8
  :elapsed_time => "%3.3f" % elapsed_time )
9
9
  end
10
10
 
11
- ::Mole.auto_check( File.join( File.dirname(__FILE__), %w[.. data] ) ) do |context, feature, boom, ret_val, block, *args|
11
+ ::Mole.auto_unchecked( File.join( File.dirname(__FILE__), %w[.. data] ) ) do |context, feature, boom, ret_val, block, *args|
12
12
  ::Mole::Moler.check_it(
13
13
  context ,
14
14
  "AppBreaker" ,
@@ -17,10 +17,10 @@ end
17
17
  :boom => boom )
18
18
  end
19
19
 
20
- ::Mole.auto_mole( File.join( File.dirname(__FILE__), %w[.. data] ) ) do |context, feature, ret, block, *args|
20
+ ::Mole.auto_after( File.join( File.dirname(__FILE__), %w[.. data] ) ) do |context, feature, ret, block, *args|
21
21
  ::Mole::Moler.mole_it(
22
22
  context ,
23
23
  feature ,
24
24
  "AppBreaker",
25
- :args => context.params[:id] )
25
+ :args => args )
26
26
  end
data/spec/data/blee.rb CHANGED
@@ -12,7 +12,12 @@ class Blee
12
12
 
13
13
  def blee_no_args
14
14
  10
15
- end
15
+ end
16
+
17
+ # Try some ßpunctuations...
18
+ def get_out?
19
+ true
20
+ end
16
21
 
17
22
  def blee_args( a, b, c, d )
18
23
  # puts ">>> Blee Many Args #{[a,b,c,d].join( "--" )}"
data/spec/module_spec.rb CHANGED
@@ -12,6 +12,14 @@ describe Module do
12
12
  CallStackChecker.reset!
13
13
  end
14
14
 
15
+ it "should handle features with punctuation correctly" do
16
+ Blee.mole_before( :feature => :get_out? ) { |context, feature, *args|
17
+ CallStackChecker.called
18
+ }
19
+ @blee.get_out?
20
+ CallStackChecker.should be_called
21
+ end
22
+
15
23
  it "should trap mole before handler exceptions" do
16
24
  Blee.mole_before( :feature => :crap_out ) { |context, feature, *args|
17
25
  raise "LEGIT !! - Before - Something did crap out"
@@ -5,7 +5,16 @@ describe Mole::Utils::Frameworks do
5
5
  ::Mole.reset_configuration!
6
6
  ::Mole.initialize( :moleable => true )
7
7
  end
8
-
8
+
9
+ describe ".flatten_params" do
10
+ it "should flatten request parameters correctly" do
11
+ Mole::Utils::Frameworks.flatten_params( RailsController.new ).should == "action => fred, controller => rails, id => 10"
12
+ end
13
+ it "should detect if this is not a controller class" do
14
+ Mole::Utils::Frameworks.flatten_params( Poro.new ).should be_nil
15
+ end
16
+ end
17
+
9
18
  describe ".features_for" do
10
19
  it "should find the correct features for a merb controller" do
11
20
  features = Mole::Utils::Frameworks.features_for( MerbController )
@@ -68,6 +77,10 @@ describe Mole::Utils::Frameworks do
68
77
  end
69
78
 
70
79
  class RailsController
80
+ def params
81
+ { :id => 10, :action => "fred", :controller => "rails" }
82
+ end
83
+
71
84
  def self.action_methods
72
85
  %w[fred blee]
73
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mole
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernand Galiana
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-21 00:00:00 -06:00
12
+ date: 2008-04-24 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency