Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 2bfe11d4e7f84ac3fb0ebfef0f029068e67e3e23 @nicksieger nicksieger committed Sep 28, 2012
Showing with 334 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +2 −0 .rspec
  3. +17 −0 Gemfile
  4. +40 −0 Gemfile.lock
  5. +13 −0 Manifest.txt
  6. +68 −0 README.md
  7. +20 −0 Rakefile
  8. +13 −0 lib/loldance.rb
  9. +53 −0 loldance.gemspec
  10. +4 −0 spec/loldance_spec.rb
  11. +5 −0 spec/spec_helper.rb
  12. +97 −0 spec/support/have_received.rb
@@ -0,0 +1,2 @@
+.DS_Store
+pkg/
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--order rand
17 Gemfile
@@ -0,0 +1,17 @@
+# -*- ruby -*-
+
+# DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
+
+source :gemcutter
+
+
+gem "rdoc", "~>3.10", :group => [:development, :test]
+gem "hoe-bundler", "~>1.1.0", :group => [:development, :test]
+gem "hoe-gemspec", "~>1.0.0", :group => [:development, :test]
+gem "hoe-git", "~>1.5.0", :group => [:development, :test]
+gem "rspec", "~>2.11.0", :group => [:development, :test]
+gem "ZenTest", "~>4.8.0", :group => [:development, :test]
+gem "rspec-given", "~>1.0", :group => [:development, :test]
+gem "hoe", "~>3.0", :group => [:development, :test]
+
+# vim: syntax=ruby
@@ -0,0 +1,40 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ ZenTest (4.8.0)
+ diff-lcs (1.1.3)
+ hoe (3.0.3)
+ rake (~> 0.8)
+ hoe-bundler (1.1.0)
+ hoe (>= 2.2.0)
+ hoe-gemspec (1.0.0)
+ hoe (>= 2.2.0)
+ hoe-git (1.5.0)
+ hoe (>= 2.2.0)
+ json (1.6.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.1)
+ rspec-expectations (2.11.3)
+ diff-lcs (~> 1.1.3)
+ rspec-given (1.5.0)
+ rspec (> 1.2.8)
+ rspec-mocks (2.11.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ ZenTest (~> 4.8.0)
+ hoe (~> 3.0)
+ hoe-bundler (~> 1.1.0)
+ hoe-gemspec (~> 1.0.0)
+ hoe-git (~> 1.5.0)
+ rdoc (~> 3.10)
+ rspec (~> 2.11.0)
+ rspec-given (~> 1.0)
@@ -0,0 +1,13 @@
+.rspec
+.rvmrc
+CHANGELOG.md
+Gemfile
+Gemfile.lock
+Manifest.txt
+README.md
+Rakefile
+lib/loldance.rb
+loldance.gemspec
+spec/#loldance_spec.rb#
+spec/spec_helper.rb
+spec/support/have_received.rb
@@ -0,0 +1,68 @@
+# loldance
+
+* http://github.com/livingsocial/loldance
+
+## DESCRIPTION:
+
+The [Stomp Dance] is described as a "drunken," "crazy," or "inspirited" dance in
+the native Creek Indian language. Not unlike what one finds when one looks for
+Ruby STOMP clients.
+
+The purpose of Loldance is to be the simplest possible Stomp client. No
+in-memory buffering of outgoing messages, no fanout subscriptions in-process, no
+transactions, no complicated messaging patterns.
+
+[Stomp Dance]: http://en.wikipedia.org/wiki/Stomp_dance
+
+## FEATURES:
+
+```
+dance = Loldance.new(["127.0.0.1:61613"])
+
+dance.publish("/queue/loldance", "craziness")
+
+# subscribe with a block that gets invoked for each message
+dance.subscribe("/queue/loldance") do |msg|
+ puts msg.body # => craziness
+end
+
+# subscribe with an object that gets #call'd
+class Dancer
+ def call(msg)
+ puts msg.body
+ end
+end
+# replaces previous subscribe block above
+dance.subscribe("/queue/loldance", Dancer.new)
+dance.unsubscribe("/queue/loldance")
+```
+
+## REQUIREMENTS / LIMITATIONS:
+
+- Only supports [Stomp 1.1](http://stomp.github.com/stomp-specification-1.1.html)
+- Only one subscription per queue per Loldance
+- Only one handler object/block per queue. If you want to multi-dispatch a
+ message, write your own dispatcher.
+- Only supports the following frames:
+ - CONNECT/CONNECTED (initial handshake)
+ - SEND
+ - SUBSCRIBE
+ - UNSUBSCRIBE
+ - DISCONNECT
+ - MESSAGE
+ - ERROR
+- Not supported:
+ - ACK/NACK
+ - BEGIN/COMMIT/ABORT
+ - RECEIPT
+ - ack/receipt headers
+
+## AUTHORS / LICENSE:
+
+* Nick Sieger <nick.sieger@livingsocial.com>
+
+The MIT License
+
+(c) 2012 LivingSocial, Inc.
+
+(put license text here)
@@ -0,0 +1,20 @@
+require 'bundler/setup'
+require 'hoe'
+
+Hoe.plugin :bundler, :git, :gemspec
+
+Hoe.spec 'loldance' do
+ developer 'Nick Sieger', 'nick.sieger@livingsocial.com'
+
+ ### Use markdown for changelog and readme
+ self.history_file = 'CHANGELOG.md'
+ self.readme_file = 'README.md'
+
+ ### dependencies!
+ self.extra_dev_deps << [ 'hoe-bundler', '~> 1.1.0' ]
+ self.extra_dev_deps << [ 'hoe-gemspec', '~> 1.0.0' ]
+ self.extra_dev_deps << [ 'hoe-git', '~> 1.5.0' ]
+ self.extra_dev_deps << [ 'rspec', '~> 2.11.0' ]
+ self.extra_dev_deps << [ 'ZenTest', '~> 4.8.0' ]
+ self.extra_dev_deps << [ 'rspec-given', '~> 1.0' ]
+end
@@ -0,0 +1,13 @@
+#
+# loldance :: loldance.rb
+#
+# LivingSocial Internal Code. Do Not Distribute.
+#
+# Authors:
+#
+# * Nick Sieger <nick.sieger@livingsocial.com>
+#
+
+class Loldance
+ VERSION = '0.0.1'
+end
@@ -0,0 +1,53 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "loldance"
+ s.version = "0.0.1.20120928194737"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Nick Sieger"]
+ s.date = "2012-09-28"
+ s.description = "The [Stomp Dance] is described as a \"drunken,\" \"crazy,\" or \"inspirited\" dance in\nthe native Creek Indian language. Not unlike what one finds when one looks for\nRuby STOMP clients.\n\nThe purpose of Loldance is to be the simplest possible Stomp client. No\nin-memory buffering of outgoing messages, no fanout subscriptions in-process, no\ntransactions, no complicated messaging patterns.\n\n[Stomp Dance]: http://en.wikipedia.org/wiki/Stomp_dance"
+ s.email = ["nick.sieger@livingsocial.com"]
+ s.extra_rdoc_files = ["Manifest.txt"]
+ s.files = [".rspec", ".rvmrc", "CHANGELOG.md", "Gemfile", "Gemfile.lock", "Manifest.txt", "README.md", "Rakefile", "lib/loldance.rb", "spec/spec_helper.rb", ".gemtest"]
+ s.homepage = "http://github.com/livingsocial/loldance"
+ s.rdoc_options = ["--main", "README.md"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = "loldance"
+ s.rubygems_version = "1.8.24"
+ s.summary = "The [Stomp Dance] is described as a \"drunken,\" \"crazy,\" or \"inspirited\" dance in the native Creek Indian language"
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
+ s.add_development_dependency(%q<hoe-bundler>, ["~> 1.1.0"])
+ s.add_development_dependency(%q<hoe-gemspec>, ["~> 1.0.0"])
+ s.add_development_dependency(%q<hoe-git>, ["~> 1.5.0"])
+ s.add_development_dependency(%q<rspec>, ["~> 2.11.0"])
+ s.add_development_dependency(%q<ZenTest>, ["~> 4.8.0"])
+ s.add_development_dependency(%q<rspec-given>, ["~> 1.0"])
+ s.add_development_dependency(%q<hoe>, ["~> 3.0"])
+ else
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
+ s.add_dependency(%q<hoe-bundler>, ["~> 1.1.0"])
+ s.add_dependency(%q<hoe-gemspec>, ["~> 1.0.0"])
+ s.add_dependency(%q<hoe-git>, ["~> 1.5.0"])
+ s.add_dependency(%q<rspec>, ["~> 2.11.0"])
+ s.add_dependency(%q<ZenTest>, ["~> 4.8.0"])
+ s.add_dependency(%q<rspec-given>, ["~> 1.0"])
+ s.add_dependency(%q<hoe>, ["~> 3.0"])
+ end
+ else
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
+ s.add_dependency(%q<hoe-bundler>, ["~> 1.1.0"])
+ s.add_dependency(%q<hoe-gemspec>, ["~> 1.0.0"])
+ s.add_dependency(%q<hoe-git>, ["~> 1.5.0"])
+ s.add_dependency(%q<rspec>, ["~> 2.11.0"])
+ s.add_dependency(%q<ZenTest>, ["~> 4.8.0"])
+ s.add_dependency(%q<rspec-given>, ["~> 1.0"])
+ s.add_dependency(%q<hoe>, ["~> 3.0"])
+ end
+end
@@ -0,0 +1,4 @@
+require 'spec_helper'
+
+describe Loldance do
+end
@@ -0,0 +1,5 @@
+require 'loldance'
+require 'rspec'
+require 'rspec-given'
+
+Dir[File.expand_path('../support/', __FILE__) + '/*.rb'].each {|f| require f }
@@ -0,0 +1,97 @@
+# Like rspec-spies, but better.
+#
+# Leverages RSpec's builtin MessageExpectation class/DSL so that you can use arg
+# matchers, # of invocation matchers, etc.
+
+require 'rspec/mocks'
+
+class RSpec::Mocks::Proxy
+ attr_reader :messages_received, :error_generator
+
+ # This does the equivalent of rspec-spies monkey patch, but with less work
+ alias orig_message_received message_received
+ def message_received(*args, &block)
+ orig_message_received(*args, &block).tap { record_message_received(*args, &block) }
+ end
+
+ # Be sure to reset the messages received between specs!
+ alias orig_reset reset
+ def reset
+ orig_reset.tap { messages_received.clear }
+ end
+end
+
+module RSpec::Mocks::Methods
+
+ def messages_received
+ __mock_proxy.messages_received
+ end
+
+ def error_generator
+ __mock_proxy.error_generator
+ end
+
+ def replay_on(other, &match_block)
+ messages_received.each do |msg, args, &block|
+ if !match_block || match_block.call(msg,args,&block)
+ other.send msg, *args, &block
+ end
+ end
+ end
+
+end
+
+class RSpec::Mocks::MessageExpectation
+ public :error_generator=
+end
+
+module RSpec::Matchers::HaveReceived
+ class Matcher
+ def initialize(message, expected_from)
+ @message, @mock = message, RSpec::Mocks::Mock.new
+ @mock.stub!(message)
+ @expectation = @mock.should_receive(message, expected_from: expected_from)
+ end
+
+ def matches?(actual)
+ begin
+ @expectation.error_generator = actual.error_generator
+ actual.replay_on(@mock) {|msg,args,&block| @message == msg }
+ @mock.rspec_verify
+ true
+ rescue RSpec::Mocks::MockExpectationError => e
+ @exception = e
+ false
+ end
+ end
+
+ def description
+ "have received #{@message.inspect}"
+ end
+
+ def failure_message_for_should
+ @exception.message
+ end
+
+ def failure_message_for_should_not
+ begin
+ @expectation.generate_error
+ rescue RSpec::Mocks::MockExpectationError => e
+ e.message.sub(/expected.*/m, "unexpected match")
+ end
+ end
+
+ def method_missing(meth, *args, &block)
+ @expectation.send meth, *args, &block
+ self
+ end
+ end
+
+ def have_received(message)
+ Matcher.new(message, caller(1)[0])
+ end
+end
+
+RSpec.configure do |config|
+ config.include RSpec::Matchers::HaveReceived
+end

0 comments on commit 2bfe11d

Please sign in to comment.