Permalink
Browse files

refactoring tests to use nginx_test_helper and rspec gems

  • Loading branch information...
1 parent 67935a7 commit 029daba7a82000f005388309519b169a57e00892 @wandenberg committed Feb 15, 2013
Showing with 6,451 additions and 9,081 deletions.
  1. +12 −34 docs/server_tests.textile
  2. +1 −0 misc/.rvmrc
  3. +23 −0 misc/Gemfile
  4. +95 −0 misc/Gemfile.lock
  5. +208 −0 misc/Rakefile
  6. +3 −4 misc/github_template.html.erb
  7. +2 −2 misc/js/pushstream.js
  8. 0 {test → misc}/spec/javascripts/PushStreamSpec.js
  9. 0 {test → misc}/spec/javascripts/PushStreamUtilsSpec.js
  10. +1 −1 {test → misc}/spec/javascripts/helpers/SpecHelper.js
  11. +61 −0 misc/spec/mix/broadcast_properties_spec.rb
  12. +588 −0 misc/spec/mix/channel_statistics_spec.rb
  13. +637 −0 misc/spec/mix/cleanup_memory_spec.rb
  14. +56 −0 misc/spec/mix/keepalive_spec.rb
  15. +166 −0 misc/spec/mix/measure_memory_spec.rb
  16. +163 −0 misc/spec/mix/send_signals_spec.rb
  17. +142 −0 misc/spec/mix/setup_parameters_spec.rb
  18. +177 −0 misc/spec/nginx_configuration.rb
  19. +30 −0 misc/spec/publisher/channel_id_collision_spec.rb
  20. +788 −0 misc/spec/publisher/properties_spec.rb
  21. +269 −0 misc/spec/publisher/publish_messages_spec.rb
  22. +61 −0 misc/spec/spec_helper.rb
  23. +148 −0 misc/spec/subscriber/comunication_properties_spec.rb
  24. +115 −0 misc/spec/subscriber/connection_cleanup_spec.rb
  25. +362 −0 misc/spec/subscriber/event_source_spec.rb
  26. +452 −0 misc/spec/subscriber/long_polling_spec.rb
  27. +176 −0 misc/spec/subscriber/padding_by_user_agent_spec.rb
  28. +387 −0 misc/spec/subscriber/polling_spec.rb
  29. +935 −0 misc/spec/subscriber/properties_spec.rb
  30. +393 −0 misc/spec/subscriber/websocket_spec.rb
  31. +0 −1 test/.rvmrc
  32. +0 −27 test/Gemfile
  33. +0 −99 test/Gemfile.lock
  34. +0 −163 test/Rakefile
  35. +0 −458 test/base_test_case.rb
  36. +0 −74 test/spec/javascripts/support/jasmine.yml
  37. +0 −23 test/spec/javascripts/support/jasmine_config.rb
  38. +0 −32 test/spec/javascripts/support/jasmine_runner.rb
  39. +0 −65 test/test_broadcast_properties.rb
  40. +0 −29 test/test_channel_id_collision.rb
  41. +0 −608 test/test_channel_statistics.rb
  42. +0 −499 test/test_cleanup_memory.rb
  43. +0 −502 test/test_cleanup_memory_after_kill.rb
  44. +0 −487 test/test_cleanup_memory_after_reload.rb
  45. +0 −170 test/test_comunication_properties.rb
  46. +0 −27 test/test_create_many_channels.rb
  47. +0 −40 test/test_keepalive.rb
  48. +0 −178 test/test_measure_memory.rb
  49. +0 −192 test/test_padding_by_user_agent.rb
  50. +0 −327 test/test_publish_messages.rb
  51. +0 −412 test/test_publisher.rb
  52. +0 −800 test/test_publisher_admin.rb
  53. +0 −156 test/test_send_signals.rb
  54. +0 −323 test/test_setup_parameters.rb
  55. +0 −1,041 test/test_subscriber.rb
  56. +0 −131 test/test_subscriber_connection_cleanup.rb
  57. +0 −419 test/test_subscriber_event_source.rb
  58. +0 −645 test/test_subscriber_long_polling.rb
  59. +0 −642 test/test_subscriber_polling.rb
  60. +0 −73 test/test_subscriber_properties.rb
  61. +0 −397 test/test_websocket.rb
View
@@ -3,49 +3,27 @@ h1(#tests). Tests <a name="tests" href="#">&nbsp;</a>
The tests for this module are written in Ruby, and are acceptance tests.
To run them is needed to have an environment with:
-* Basic requirements
-** ruby >= 1.8.7
-** rubygems >= 1.6.2
-** rake >= 0.8.7
-* Required gems
-** POpen4 >= 0.1.4
-** em-http-request >= 0.2.14
-** json >= 1.4.3
-** ruby-debug >= 0.10.4
-** jasmine >= 1.0.2.1
-** nokogiri >= 1.5.0
-** jshint >= 0.1.1
-
-You can install these gems with bundler (bundler is required to be installed before, _gem install bundler_)
+* ruby >= 1.9.3
+* bundler >= 1.1.4
-<pre>
-cd test/
-bundle install --without docs
-</pre>
-
-or individually
+and install required gems doing:
<pre>
-gem install POpen4 -v 0.1.4
-gem install em-http-request -v 0.2.14
-gem install json -v 1.4.3
-gem install ruby-debug -v 0.10.4
-gem install jasmine -v 1.0.2.1
-gem install nokogiri -v 1.5.0
-gem install jshint -v 0.1.1
+cd misc/
+bundle install --without docs
</pre>
-Then issue @rake tests@.
-This command run the tests using nginx *executable* located at _/usr/local/nginx/sbin/nginx_ with _1_ *worker* responding at *host* _localhost_ and *port* _9990_.
+Then issue @rake spec@.
+This command run the tests using nginx *executable* located at _/usr/local/nginx/sbin/nginx_ with _1_ *worker* responding at *host* _127.0.0.1_ and *port* _9990_.
To change this behavior use the commands bellow
<pre>
-rake tests executable="../build/nginx-1.1.15/objs/nginx" # to change default path for nginx executable
-rake tests host=my_machine # to change default hostname
-rake tests port=9889 # to change default port
-rake tests workers=2 # to change dafault number of workers used
+NGINX_EXEC="../build/nginx-1.1.15/objs/nginx" rake spec # to change default path for nginx executable
+NGINX_HOST="my_machine" rake spec # to change default hostname
+NGINX_PORT=9889 rake spec # to change default port
+NGINX_WORKERS=2 rake spec # to change dafault number of workers used
and can combine any of these parameters, like:
-rake tests port=9889 executable="../build/nginx-1.1.15/objs/nginx"
+NGINX_PORT=9889 NGINX_EXEC="../build/nginx-1.1.15/objs/nginx" rake spec
</pre>
View
@@ -0,0 +1 @@
+rvm ruby-1.9.3-p194@nginx-push-stream-module --create
View
@@ -0,0 +1,23 @@
+source "https://rubygems.org"
+
+gem 'rake', '~> 10.0.3'
+
+group :test do
+ gem 'rspec', '~> 2.12.0'
+ gem 'em-http-request', '~> 1.0.3'
+ gem 'nginx_test_helper', '~> 0.0.1'
+ gem 'jshintrb', '~> 0.2.1'
+ gem 'therubyracer', '~> 0.11.3'
+ gem 'jasmine', '~> 1.3.1'
+ gem 'listen', '~> 0.7.2'
+ gem 'rb-inotify', '~> 0.8.8'
+ gem 'json', '~> 1.7.6'
+
+ gem 'debugger', '~> 1.3.1'
+end
+
+group :docs do
+ gem 'github-markup', '~> 0.7.5', :require => 'github/markup'
+ gem 'RedCloth', '~> 4.2.9'
+ gem 'nokogiri', '~> 1.5.6'
+end
View
@@ -0,0 +1,95 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ Platform (0.4.0)
+ RedCloth (4.2.9)
+ addressable (2.3.2)
+ childprocess (0.3.8)
+ ffi (~> 1.0, >= 1.0.11)
+ columnize (0.3.6)
+ cookiejar (0.3.0)
+ debugger (1.3.1)
+ columnize (>= 0.3.1)
+ debugger-linecache (~> 1.1.1)
+ debugger-ruby_core_source (~> 1.1.8)
+ debugger-linecache (1.1.2)
+ debugger-ruby_core_source (>= 1.1.1)
+ debugger-ruby_core_source (1.1.8)
+ diff-lcs (1.1.3)
+ em-http-request (1.0.3)
+ addressable (>= 2.2.3)
+ cookiejar
+ em-socksify
+ eventmachine (>= 1.0.0.beta.4)
+ http_parser.rb (>= 0.5.3)
+ em-socksify (0.2.1)
+ eventmachine (>= 1.0.0.beta.4)
+ eventmachine (1.0.0)
+ execjs (1.4.0)
+ multi_json (~> 1.0)
+ ffi (1.3.1)
+ github-markup (0.7.5)
+ http_parser.rb (0.5.3)
+ jasmine (1.3.1)
+ jasmine-core (~> 1.3.1)
+ rack (~> 1.0)
+ rspec (>= 1.3.1)
+ selenium-webdriver (>= 0.1.3)
+ jasmine-core (1.3.1)
+ jshintrb (0.2.1)
+ execjs
+ multi_json (>= 1.3)
+ rake
+ json (1.7.6)
+ libv8 (3.11.8.13)
+ listen (0.7.2)
+ multi_json (1.5.0)
+ nginx_test_helper (0.0.1)
+ popen4
+ nokogiri (1.5.6)
+ open4 (1.3.0)
+ popen4 (0.1.2)
+ Platform (>= 0.4.0)
+ open4 (>= 0.4.0)
+ rack (1.5.2)
+ rake (10.0.3)
+ rb-inotify (0.8.8)
+ ffi (>= 0.5.0)
+ ref (1.0.2)
+ rspec (2.12.0)
+ rspec-core (~> 2.12.0)
+ rspec-expectations (~> 2.12.0)
+ rspec-mocks (~> 2.12.0)
+ rspec-core (2.12.2)
+ rspec-expectations (2.12.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.12.2)
+ rubyzip (0.9.9)
+ selenium-webdriver (2.29.0)
+ childprocess (>= 0.2.5)
+ multi_json (~> 1.0)
+ rubyzip
+ websocket (~> 1.0.4)
+ therubyracer (0.11.3)
+ libv8 (~> 3.11.8.12)
+ ref
+ websocket (1.0.7)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ RedCloth (~> 4.2.9)
+ debugger (~> 1.3.1)
+ em-http-request (~> 1.0.3)
+ github-markup (~> 0.7.5)
+ jasmine (~> 1.3.1)
+ jshintrb (~> 0.2.1)
+ json (~> 1.7.6)
+ listen (~> 0.7.2)
+ nginx_test_helper (~> 0.0.1)
+ nokogiri (~> 1.5.6)
+ rake (~> 10.0.3)
+ rb-inotify (~> 0.8.8)
+ rspec (~> 2.12.0)
+ therubyracer (~> 0.11.3)
View
@@ -0,0 +1,208 @@
+project_dir = File.expand_path('..', File.dirname(__FILE__))
+javascript_dir = File.expand_path(Dir["#{project_dir}/**/js"].first)
+
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('./Gemfile', File.dirname(__FILE__))
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
+Bundler.require(:default, :test) if defined?(Bundler)
+
+begin
+ require "rspec/core/rake_task"
+
+ desc "Run all examples"
+ RSpec::Core::RakeTask.new(:spec) do |t|
+ t.rspec_opts = %w[--color --debug]
+ t.pattern = '**/*_spec.rb'
+ end
+rescue LoadError
+ task :spec do
+ abort "RSpec is not available. In order to run rspec, you must: (sudo) gem install rspec"
+ end
+end
+
+begin
+ load 'jasmine/tasks/jasmine.rake'
+
+ task "jasmine:require" => ["jshint", "configure_jasmine", "monitor_js"]
+
+ task :configure_jasmine do
+ Jasmine.configure do |config|
+ config.spec_dir = project_dir
+ config.spec_files = lambda { Dir["#{project_dir}/misc/spec/javascripts/helpers/**/*.js"] + Dir["#{project_dir}/misc/**/*[sS]pec.js"] }
+ js_tmp_dir = File.expand_path('pushstream/js', Dir.tmpdir)
+ config.src_dir = js_tmp_dir
+ config.src_files = lambda { Dir["#{js_tmp_dir}/**/*.js"] }
+ end
+ end
+
+ task :monitor_js do
+ copy_inner_js = Proc.new do |modified, added, removed|
+ modified.each do |file|
+ destiny_path = File.dirname(file).gsub(/.*\/js\/?/, File.expand_path('pushstream/js', Dir.tmpdir))
+ FileUtils.mkdir_p(destiny_path)
+ content = File.read file
+ content.gsub!('(function (window, document, undefined) {', '')
+ content.gsub!('if (window.PushStream) { return; }', '')
+ content.gsub!('})(window, document);', '')
+ File.open(File.join(destiny_path, File.basename(file)), 'w') {|f| f.write content }
+ end
+ end
+
+ copy_inner_js.call([[File.expand_path('misc/js/pushstream.js', project_dir)], [], []])
+ listener = Listen.to(File.expand_path('misc/js', project_dir), :filter => /\.js$/)
+ listener.change(&copy_inner_js)
+ listener.start(false)
+ end
+rescue LoadError
+ desc "Run javascript tests"
+ task :jasmine do
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
+ end
+end
+
+begin
+ require "jshintrb/jshinttask"
+ Jshintrb::JshintTask.new :jshint do |t|
+ t.pattern = "#{javascript_dir}/pushstream.js"
+ t.options = :defaults
+ end
+rescue LoadError
+ desc "Run jshint on js"
+ task :jshint do
+ abort "Jshintrb is not available. In order to run jshint, you must: (sudo) gem install jshintrb"
+ end
+end
+
+namespace :docs do
+
+begin
+ Bundler.require(:default, :docs) if defined?(Bundler)
+
+ task :get_static_files do
+ base_path = File.expand_path('pushstream/docs/preview', Dir.tmpdir)
+ FileUtils.mkdir_p("#{base_path}/css")
+
+ download_file("https://a248.e.akamai.net/assets.github.com/assets/github-00f65189aa131d891441bde58bf26d999ab4d29c.css", "#{base_path}/css/github.css") unless File.exists?("#{base_path}/css/github.css")
+ download_file("https://a248.e.akamai.net/assets.github.com/assets/github2-90ff47ca514fab587fdf9f40626c56af77a8fa6b.css", "#{base_path}/css/github2.css") unless File.exists?("#{base_path}/css/github2.css")
+ end
+
+ desc "Generates docs files to preview."
+ task :generate => :get_static_files do
+ require 'erb'
+ template = ERB.new File.read("#{project_dir}/misc/github_template.html.erb")
+ base_path = File.expand_path('pushstream/docs/preview', Dir.tmpdir)
+
+ Dir.glob("#{project_dir}/**/*.textile").each do |file|
+ filename = File.basename(file)
+ content = GitHub::Markup.render(file, File.read(file))
+ rendered = template.result(binding)
+ output = file.gsub(project_dir, File.expand_path('pushstream/docs/preview', Dir.tmpdir)).gsub(".textile", ".html")
+ output_dir = File.dirname(output)
+ FileUtils.mkdir_p(output_dir)
+ File.open(output, 'w') {|f| f.write(rendered) }
+ puts "Preview rendered to #{output}"
+ end
+ end
+
+ desc "Convert docs to Nginx wiki format."
+ task :convert_to_wiki do
+ Dir.glob("#{project_dir}/**/*.textile").each do |file|
+ filename = File.basename(file)
+ content = File.read(file)
+
+ output = file.gsub(project_dir, File.expand_path('pushstream/docs/html', Dir.tmpdir)).gsub(".textile", ".html")
+ output_wiki = file.gsub(project_dir, File.expand_path('pushstream/docs/wiki', Dir.tmpdir)).gsub(".textile", ".wiki")
+ FileUtils.mkdir_p(File.dirname(output))
+ FileUtils.mkdir_p(File.dirname(output_wiki))
+
+ File.open(output, 'w') {|f| f.write(RedCloth.new(content).to_html) }
+ File.open(output_wiki, 'w') {|f| f.write(convert_to_wiki_syntax(content)) }
+ puts "Wiki converted to #{output_wiki}"
+ end
+ end
+rescue LoadError
+ desc "Generates docs files to preview."
+ task :generate do
+ abort "github-markup is not available. In order to run docs:generate, you must: (sudo) gem install github-markup"
+ end
+
+ desc "Convert docs to Nginx wiki format."
+ task :convert_to_wiki do
+ abort "RedCloth or nokogiri is not available. In order to run docs:convert_to_wiki, you must: (sudo) gem install RedCloth nokogiri"
+ end
+end
+
+ def download_file(url, output_file)
+ EventMachine.run do
+ http = EventMachine::HttpRequest.new(url).get
+ http.errback { EM.stop }
+ http.callback do
+ File.open(output_file, "w") { |f| f.write(http.response) } if (http.response_header.status == 200)
+ EM.stop
+ end
+ end
+ end
+
+ def convert_to_wiki_syntax(text)
+ doc = Nokogiri::HTML(RedCloth.new(text).to_html)
+ convert_elements(doc.children.to_a)
+ end
+
+ def convert_elements(nodes)
+ result = ""
+ nodes.each do |node|
+ if node.element? && !node.text?
+ childrens = node.children.to_a
+ unless childrens.empty?
+ result += convert_element(convert_elements(childrens), node)
+ end
+ elsif node.text?
+ result += node.text
+ end
+ end
+ result
+ end
+
+ def convert_element(text, node)
+ tag = node.name
+ text ||= ""
+ case tag
+ when "strong"
+ "'''#{text}'''"
+ when "b"
+ "'''#{text}'''"
+ when "em"
+ "''#{text}''"
+ when "h1"
+ "\n= #{text} ="
+ when "h2"
+ "\n== #{text} =="
+ when "h3"
+ "\n=== #{text} ==="
+ when "h4"
+ "\n==== #{text} ===="
+ when "h5"
+ "\n===== #{text} ====="
+ when "h6"
+ "\n====== #{text} ======"
+ when "p"
+ "\n#{text}"
+ when "a"
+ if node.attributes['href'].value.start_with?("#")
+ "[[#{node.attributes['href'].value}|#{text}]]"
+ else
+ "[#{node.attributes['href'].value} #{text}]"
+ end
+ when "html"
+ text
+ when "body"
+ text
+ when "span"
+ text
+ else
+ "<#{tag}>#{text}</#{tag}>"
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 029daba

Please sign in to comment.