message-recorder 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ == 1.0.0 2008-02-13
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Simon Menke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/message-recorder.rb
9
+ lib/message-recorder/branching_mock.rb
10
+ lib/message-recorder/chain.rb
11
+ lib/message-recorder/chaining_mock.rb
12
+ lib/message-recorder/collector.rb
13
+ lib/message-recorder/message.rb
14
+ lib/message-recorder/recorder.rb
15
+ lib/message-recorder/version.rb
16
+ log/debug.log
17
+ script/destroy
18
+ script/generate
19
+ script/txt2html
20
+ setup.rb
21
+ spec/chain_spec.rb
22
+ spec/collector_spec.rb
23
+ spec/fob_spec.rb
24
+ spec/message_spec.rb
25
+ spec/spec.opts
26
+ spec/spec_helper.rb
27
+ tasks/deployment.rake
28
+ tasks/environment.rake
29
+ tasks/rspec.rake
30
+ tasks/website.rake
31
+ website/index.html
32
+ website/index.txt
33
+ website/javascripts/rounded_corners_lite.inc.js
34
+ website/stylesheets/screen.css
35
+ website/template.rhtml
@@ -0,0 +1,63 @@
1
+ = message recorder
2
+
3
+ == What
4
+
5
+ <tt>Message::Recorder</tt> is a tool to record messages send to Ruby objects.
6
+
7
+
8
+ == Installing
9
+
10
+ sudo gem install message-recorder
11
+
12
+ == The basics
13
+
14
+ This snippet will first record a <tt>downcase</tt> message and after that it will replay the recorded messages on some objects.
15
+
16
+ recorder = Message::Recorder.new
17
+ recorder.record.downcase
18
+ recorder.send_to("HELLO") # => ["hello"]
19
+ recorder.send_to("WORLD") # => ["world"]
20
+
21
+ This is an example of branching. the <tt>with_results</tt> method accepts a block which is used to define multiple message chains at once.
22
+
23
+ recorder = Message::Recorder.new
24
+ recorder.record.downcase.with_results do
25
+ intern
26
+ capitalize
27
+ end
28
+
29
+ recorder.send_to("HELLO") # => [:hello, "Hello"]
30
+
31
+ == Demonstration of usage
32
+
33
+ This is a more complex example with nested branches.
34
+
35
+ recorder = Message::Recorder.new
36
+ recorder.record.compact.with_result do
37
+ collect { |s| s.intern }
38
+ collect { |s| s.capitalize }.with_results do
39
+ collect { |s| s.concat " world" }
40
+ collect { |s| s.concat " simon" }
41
+ end.with_results do
42
+ collect { |s| s.concat "!" }
43
+ collect { |s| s.concat "?" }
44
+ end
45
+ end
46
+
47
+ results = recorder.send_to([nil, "hello", nil, "bye", nil])
48
+ results == [ # the result is ...
49
+ [:hello, :bye],
50
+ ["Hello world!", "Bye world!"],
51
+ ["Hello simon!", "Bye simon!"],
52
+ ["Hello world?", "Bye world?"],
53
+ ["Hello simon?", "Bye simon?"]
54
+ ]
55
+
56
+ == License
57
+
58
+ This code is free to use under the terms of the MIT license.
59
+
60
+ == Contact
61
+
62
+ Comments are welcome. Send an email to Simon Menke mailto:simon@5xm.org
63
+
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,70 @@
1
+ require 'message-recorder/version'
2
+
3
+ AUTHOR = 'Simon Menke' # can also be an array of Authors
4
+ EMAIL = "simon@5xm.org"
5
+ DESCRIPTION = "Record messages send to Ruby objects so you can replay them later on. (endlessly ;)"
6
+ GEM_NAME = 'message-recorder' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'message-recorde' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Message::VERSION::STRING # + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'message-recorder documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.developer(AUTHOR, EMAIL)
52
+ p.description = DESCRIPTION
53
+ p.summary = DESCRIPTION
54
+ p.url = HOMEPATH
55
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
+ p.test_globs = ["test/**/test_*.rb"]
57
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
+
59
+ # == Optional
60
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+
63
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
+
65
+ end
66
+
67
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'message-recorder'
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2008 Simon Menke
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ $:.unshift File.dirname(__FILE__)
23
+
24
+ module Message ; end
25
+
26
+ require File.join(File.dirname(__FILE__), "message-recorder", "recorder")
27
+ require File.join(File.dirname(__FILE__), "message-recorder", "message")
28
+ require File.join(File.dirname(__FILE__), "message-recorder", "chain")
29
+ require File.join(File.dirname(__FILE__), "message-recorder", "collector")
30
+ require File.join(File.dirname(__FILE__), "message-recorder", "branching_mock")
31
+ require File.join(File.dirname(__FILE__), "message-recorder", "chaining_mock")
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2008 Simon Menke
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Message::Recorder::BranchingMock # :nodoc:
23
+ alias_method :__instance_eval__, :instance_eval
24
+ instance_methods.each { |m| undef_method m unless m =~ /^__/ }
25
+
26
+ def initialize(collector)
27
+ @branched_collectors = []
28
+ @collector_prototype = collector.deep_copy
29
+ @collector = collector.clear
30
+ end
31
+ def __branch__(&block)
32
+ __instance_eval__(&block) unless block.nil?
33
+ @branched_collectors.each { |branched_collector| @collector.concat branched_collector }
34
+ Message::Recorder::ChainingMock.new(@collector)
35
+ end
36
+ def method_missing(m, *args, &block)
37
+ branched_collector = @collector_prototype.branch
38
+ @branched_collectors << branched_collector
39
+
40
+ branched_collector.record(m, *args, &block)
41
+ Message::Recorder::ChainingMock.new(branched_collector)
42
+ end
43
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2008 Simon Menke
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+
23
+ class Message::Recorder::Chain < ::Array # :nodoc:
24
+
25
+ def initialize(array=[])
26
+ super(array)
27
+ end
28
+
29
+ def record(m, *args, &block)
30
+ push Message::Recorder::Message.new(m, *args, &block)
31
+ end
32
+
33
+ def send_to(subject_, recorder)
34
+ inject(subject_) do |subject,message|
35
+ return nil if recorder.break_if.call(subject)
36
+
37
+ message.send_to(subject, recorder)
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright (c) 2008 Simon Menke
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+
23
+ # ChainingMock is the mock object returned by the Message::Recorder#record method.
24
+ class Message::Recorder::ChainingMock
25
+ instance_methods.each { |m| undef_method m unless m =~ /^__/ }
26
+
27
+ def initialize(collector) # :nodoc:
28
+ @collector = collector
29
+ end
30
+
31
+ def method_missing(m, *args, &block) # :nodoc:
32
+ @collector.record(m, *args, &block)
33
+ return self
34
+ end
35
+
36
+ # when a block is passed to __branch__ it will create a separate call chain for each method call.
37
+ # recorder.record.__branch__ do
38
+ # hello
39
+ # bye
40
+ # end
41
+ # recorder.send_to subject
42
+ # is the same as
43
+ # recorder.record.hello
44
+ # recorder.send_to subject
45
+ #
46
+ # recorder.record.bye
47
+ # recorder.send_to subject
48
+ def __branch__(&block)
49
+ Message::Recorder::BranchingMock.new(@collector).__branch__(&block)
50
+ end
51
+ alias_method :with_results, :__branch__
52
+ alias_method :with_result, :__branch__
53
+ alias_method :branch, :__branch__
54
+
55
+ end
@@ -0,0 +1,52 @@
1
+ # Copyright (c) 2008 Simon Menke
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Message::Recorder::Collector < ::Array # :nodoc:
23
+
24
+ def initialize(array=[], root=nil)
25
+ super(array)
26
+ push ::Message::Recorder::Chain.new if self.empty?
27
+ root_collector = root
28
+ end
29
+
30
+ def collect_messages
31
+ ::Message::Recorder::ChainingMock.new(self)
32
+ end
33
+
34
+ def record(m, *args, &block)
35
+ each { |chain| chain.record(m, *args, &block) }
36
+ end
37
+
38
+ def branch
39
+ self.deep_copy
40
+ end
41
+
42
+ def deep_copy
43
+ ::Message::Recorder::Collector.new(collect { |chain| chain.dup })
44
+ end
45
+
46
+ def send_to(subject, recorder)
47
+ results = ::Array.new
48
+ each { |chain| results << chain.send_to(subject, recorder) }
49
+ results
50
+ end
51
+
52
+ end