monkey-lib 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -39,9 +39,22 @@ else
39
39
  exit 1
40
40
  end
41
41
 
42
+ def backend_available?(backend = nil)
43
+ require backend unless backend.nil?
44
+ true
45
+ rescue LoadError
46
+ false
47
+ end
48
+
42
49
  def spec_task(name, backend = nil, mode = nil)
43
50
  desc "runs specs #{"with backend #{backend} " if backend}#{"(#{mode} mode)" if mode}"
44
- define_spec_task(name, "BACKEND=#{backend.to_s.inspect} BACKEND_SETUP=#{mode.to_s.inspect} #{ENV['RUBY'] || RUBY}", "spec/monkey/**/*_spec.rb")
51
+ if backend_available? backend
52
+ define_spec_task(name, "BACKEND=#{backend.to_s.inspect} BACKEND_SETUP=#{mode.to_s.inspect} #{ENV['RUBY'] || RUBY}", "spec/monkey/**/*_spec.rb")
53
+ else
54
+ task(name) do
55
+ puts "", "could not load #{backend.inspect}, skipping specs."
56
+ end
57
+ end
45
58
  end
46
59
 
47
60
  task :environment do
@@ -3,6 +3,12 @@ module Monkey
3
3
  module Array
4
4
  # Defined by backend.
5
5
  expects :extract_options!
6
+
7
+ def select!(&block)
8
+ return :to_enum if block.nil? and respond_to? :to_enum
9
+ replace select(&block)
10
+ end
11
+
6
12
  end
7
13
  end
8
14
  end
@@ -1,6 +1,7 @@
1
1
  require __FILE__.sub(%r{monkey/.*$}, "spec_helper")
2
2
 
3
3
  describe Monkey::Ext::Array do
4
+
4
5
  describe "backend expectations" do
5
6
  # expects :extract_options!
6
7
  it "imports extract_options! from backend" do
@@ -15,4 +16,20 @@ describe Monkey::Ext::Array do
15
16
  ary2.should == [{:x => 10}, :foo]
16
17
  end
17
18
  end
19
+
20
+ describe "select!" do
21
+
22
+ it "results in the same arrays as Array#select" do
23
+ ([1, 2, 3, 4, 5, 6].select! { |e| e > 3 }).should == ([1, 2, 3, 4, 5, 6].select { |e| e > 3 })
24
+ ([1, 2, 3, 4, 5, 6].select! { |e| e < 0 }).should == ([1, 2, 3, 4, 5, 6].select { |e| e < 0 })
25
+ end
26
+
27
+ it "modifies the current array, rather than returning a new one" do
28
+ x = [1, 2, 3, 4, 5, 6]
29
+ x.select! { |e| e > 3 }
30
+ x.should == [4, 5, 6]
31
+ end
32
+
33
+ end
34
+
18
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkey-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-18 00:00:00 +01:00
12
+ date: 2009-12-20 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15