flexmock 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,6 +1,11 @@
1
1
  = Changes for FlexMock
2
2
 
3
- == Pre-Version 0.7.0
3
+ == Pre-Version 0.7.1
4
+
5
+ * Updated install.rb to handle non-root destination directories via
6
+ DESTDIR.
7
+
8
+ == Version 0.7.0
4
9
 
5
10
  * Added +and_yield+ as an expectation clause.
6
11
  * Inspect on Mocks now yield a more consise description.
data/README CHANGED
@@ -3,7 +3,7 @@
3
3
  FlexMock is a simple, but flexible, mock object library for Ruby unit
4
4
  testing.
5
5
 
6
- Version :: 0.7.0
6
+ Version :: 0.7.1
7
7
 
8
8
  = Links
9
9
 
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ require 'rake/contrib/rubyforgepublisher'
19
19
  CLEAN.include('*.tmp')
20
20
  CLOBBER.include("html", 'pkg')
21
21
 
22
- PKG_VERSION = '0.7.0'
22
+ PKG_VERSION = '0.7.1'
23
23
 
24
24
  PKG_FILES = FileList[
25
25
  '[A-Z]*',
@@ -0,0 +1,93 @@
1
+ = FlexMock 0.7.1 Released
2
+
3
+ FlexMock is a flexible mocking library for use in unit testing and behavior
4
+ specification in Ruby. Version 0.7.1 includes a minor bug fix.
5
+
6
+ == Bug Fixes n 0.7.1
7
+
8
+ * A bug in demeter mocking in 0.7.0 prevented the mocking of
9
+ operators. This has been fixed.
10
+
11
+ == What is FlexMock?
12
+
13
+ FlexMock is a flexible framework for creating mock object for testing. When
14
+ running unit tests, it is often desirable to use isolate the objects being
15
+ tested from the "real world" by having them interact with simplified test
16
+ objects. Sometimes these test objects simply return values when called, other
17
+ times they verify that certain methods were called with particular arguments
18
+ in a particular order.
19
+
20
+ FlexMock makes creating these test objects easy.
21
+
22
+ === Features
23
+
24
+ * Easy integration with both Test::Unit and RSpec. Mocks created with the
25
+ flexmock method are automatically verified at the end of the test or
26
+ example.
27
+
28
+ * A fluent interface that allows mock behavior to be specified very
29
+ easily.
30
+
31
+ * A "record mode" where an existing implementation can record its
32
+ interaction with a mock for later validation against a new
33
+ implementation.
34
+
35
+ * Easy mocking of individual methods in existing, non-mock objects.
36
+
37
+ * Easy mocking of chains of method calls.
38
+
39
+ * The ability to cause classes to instantiate test instances (instead of real
40
+ instances) for the duration of a test.
41
+
42
+ === Example
43
+
44
+ Suppose you had a Dog object that wagged a tail when it was happy.
45
+ Something like this:
46
+
47
+ class Dog
48
+ def initialize(a_tail)
49
+ @tail = a_tail
50
+ end
51
+ def happy
52
+ @tail.wag
53
+ end
54
+ end
55
+
56
+ To test the +Dog+ class without a real +Tail+ object (perhaps because
57
+ real +Tail+ objects activate servos in some robotic equipment), you
58
+ can do something like this:
59
+
60
+ require 'test/unit'
61
+ require 'flexmock/test_unit'
62
+
63
+ class TestDog < Test::Unit::TestCase
64
+ def test_dog_wags_tail_when_happy
65
+ tail = flexmock("tail")
66
+ tail.should_receive(:wag).once
67
+ dog = Dog.new(tail)
68
+ dog.happy
69
+ end
70
+ end
71
+
72
+ FlexMock will automatically verify that the mocked tail object received the
73
+ message +wag+ exactly one time. If it doesn't, the test will not pass.
74
+
75
+ See the FlexMock documentation at http://flexmock.rubyforge.org for details on
76
+ specifying arguments and return values on mocked methods, as well as a simple
77
+ technique for mocking tail objects when the Dog class creates the tail objects
78
+ directly.
79
+
80
+ == Availability
81
+
82
+ You can make sure you have the latest version with a quick RubyGems command:
83
+
84
+ gem install flexmock (you may need root/admin privileges)
85
+
86
+ Otherwise, you can get it from the more traditional places:
87
+
88
+ Download:: http://rubyforge.org/project/showfiles.php?group_id=170
89
+
90
+ You will find documentation at: http://flexmock.rubyforge.org.
91
+
92
+ -- Jim Weirich
93
+
data/install.rb CHANGED
@@ -26,6 +26,14 @@ unless $sitedir
26
26
  end
27
27
  end
28
28
 
29
+ if (destdir = ENV['DESTDIR'])
30
+ $sitedir = destdir + $sitedir
31
+ File::makedirs($sitedir)
32
+ end
33
+
34
+ flexmock_dest = File.join($sitedir, "flexmock")
35
+ File::makedirs(flexmock_dest, true)
36
+ File::chmod(0755, flexmock_dest)
29
37
  # The library files
30
38
 
31
39
  file = 'flexmock.rb'
@@ -303,11 +303,13 @@ class FlexMock
303
303
  end
304
304
  end
305
305
 
306
+ METHOD_NAME_RE = /^([A-Za-z_][A-Za-z0-9_]*[=!?]?|\[\]=?||\*\*|<<|>>|<=>|[<>=]=|=~|===|[-+]@|[-+\*\/%&^|<>~])$/
307
+
306
308
  # Check that all the names in the list are valid method names.
307
309
  def check_method_names(names)
308
310
  names.each do |name|
309
311
  fail FlexMock::UsageError, "Ill-formed method name '#{name}'" if
310
- name !~ /^[A-Za-z_][A-Za-z0-9_]*[=!?]?$/
312
+ name !~ METHOD_NAME_RE
311
313
  end
312
314
  end
313
315
  end
@@ -16,6 +16,21 @@ class TestDemeterMocking < Test::Unit::TestCase
16
16
  assert_equal :first, m.children.first
17
17
  end
18
18
 
19
+ def test_demeter_mocking_with_operators
20
+ m = flexmock("A")
21
+ m.should_receive("children.+@.last").and_return(:value)
22
+ assert_kind_of FlexMock, m
23
+ assert_kind_of FlexMock, m.children
24
+ assert_kind_of FlexMock, + m.children
25
+ assert_equal :value, (+ m.children).last
26
+ end
27
+
28
+ def test_demeter_mocking_with_multiple_operators
29
+ m = flexmock("A")
30
+ m.should_receive("+@.-@.~").and_return(:value)
31
+ assert_equal :value, ~-+m
32
+ end
33
+
19
34
  def test_multiple_demeter_mocks_on_same_branch_is_ok
20
35
  m = flexmock("A")
21
36
  m.should_receive("child.x.y.z.first").and_return(:first)
@@ -865,6 +865,41 @@ class TestFlexMockShoulds < Test::Unit::TestCase
865
865
  assert_equal :mkf, m2.mock_kernel_function
866
866
  end
867
867
 
868
+ def test_can_mock_operators
869
+ assert_operator(:[]) { |m| m[1] }
870
+ assert_operator(:[]=) { |m| m[1] = :value }
871
+ assert_operator(:**) { |m| m ** :x }
872
+ assert_operator(:+@) { |m| +m }
873
+ assert_operator(:-@) { |m| -m }
874
+ assert_operator(:+) { |m| m + :x }
875
+ assert_operator(:-) { |m| m - :x }
876
+ assert_operator(:*) { |m| m * :x }
877
+ assert_operator(:"/") { |m| m / :x }
878
+ assert_operator(:%) { |m| m % :x }
879
+ assert_operator(:~) { |m| ~m }
880
+ assert_operator(:&) { |m| m & :x }
881
+ assert_operator(:|) { |m| m | :x }
882
+ assert_operator(:^) { |m| m ^ :x }
883
+ assert_operator(:<) { |m| m < :x }
884
+ assert_operator(:>) { |m| m > :x }
885
+ assert_operator(:>=) { |m| m >= :x }
886
+ assert_operator(:<=) { |m| m <= :x }
887
+ assert_operator(:==) { |m| m == :x }
888
+ assert_operator(:===) { |m| m === :x }
889
+ assert_operator(:<<) { |m| m << :x }
890
+ assert_operator(:>>) { |m| m >> :x }
891
+ assert_operator(:<=>) { |m| m <=> :x }
892
+ assert_operator(:=~) { |m| m =~ :x }
893
+ end
894
+
895
+ private
896
+
897
+ def assert_operator(op, &block)
898
+ m = flexmock("mock")
899
+ m.should_receive(op).and_return(:value)
900
+ assert_equal :value, block.call(m)
901
+ end
902
+
868
903
  end
869
904
 
870
905
  class TestFlexMockShouldsWithInclude < Test::Unit::TestCase
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: flexmock
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.0
7
- date: 2007-09-01 00:00:00 -04:00
6
+ version: 0.7.1
7
+ date: 2007-09-24 00:00:00 -04:00
8
8
  summary: Simple and Flexible Mock Objects for Testing
9
9
  require_paths:
10
10
  - lib
@@ -86,6 +86,7 @@ files:
86
86
  - doc/releases/flexmock-0.6.3.rdoc
87
87
  - doc/releases/flexmock-0.6.4.rdoc
88
88
  - doc/releases/flexmock-0.7.0.rdoc
89
+ - doc/releases/flexmock-0.7.1.rdoc
89
90
  test_files: []
90
91
 
91
92
  rdoc_options:
@@ -110,6 +111,7 @@ extra_rdoc_files:
110
111
  - doc/releases/flexmock-0.6.3.rdoc
111
112
  - doc/releases/flexmock-0.6.4.rdoc
112
113
  - doc/releases/flexmock-0.7.0.rdoc
114
+ - doc/releases/flexmock-0.7.1.rdoc
113
115
  executables: []
114
116
 
115
117
  extensions: []