rspectacles 0.0.6 → 0.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92fd52dccf56cd933bfa9361092dd7590e767cd8
4
- data.tar.gz: d58bfa299fdfb27798a1de5d8e4e578318dea9d7
3
+ metadata.gz: 55a26564ce13d66c487172e032524359c5440e6d
4
+ data.tar.gz: cb85f1910af0e08b2cc4ad8bead4cdc671057b89
5
5
  SHA512:
6
- metadata.gz: aa73df7297d3b0daaf259c41ae0068c52ef1a84f3ba6909f33356d459ccf8c8803a5dbefce4b74a09c8ad8c8189df12889990615d946fa429ed42937a0efb354
7
- data.tar.gz: 5c05f8a496b3f28f99f06a1a9e07add764f64cfebd0bd4a5789bec0e3c7612c183247587f4430fe503bc4ad07096931e532f2c05bdc21120c86de6e300dcf1aa
6
+ metadata.gz: bf43b503e80ca48f4babc6e9830ffcfe305bb96b9f8e7273c4b04e97a33c0d28218fc2a4f6ed01cfce6a9e843940915ce166a5f09a73c26dea0bd11cd8c18a70
7
+ data.tar.gz: 1e43d2e4f4307a0d61daeaf2ad1412563abf543aa87f8e906677fb248a5e7698b874346f2d55c24396b9d7c3de4dab579243ee5e1ba94d927b647fbac09ef7fe
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspectacles (0.0.6)
4
+ rspectacles (0.0.7)
5
5
  em-hiredis (~> 0.2.1)
6
6
  rake
7
7
  redis
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # RSpectacles
2
+
3
+ RSpectacles is an in-browser visualizer and profiler for RSpec. It uses
4
+ Server-Sent Events, Redis, and d3.js to render a
5
+ [partition](http://bl.ocks.org/mbostock/4063423) of your specs in real time, so
6
+ that you can tell at a glance where the time is spent in your test suite.
7
+
8
+ As a Sinatra app it can be run standalone, or else mounted on another Rack app.
9
+
10
+ ## Installation
11
+
12
+ gem install rspectacles
13
+
14
+ Or in your Gemfile:
15
+
16
+ group :test, :development do
17
+ gem 'rspectacles'
18
+ end
19
+
20
+ Then add the formatter to your .rspec file:
21
+
22
+ --require 'rspectacles/redis_formatter'
23
+ --format RSpectacles::RedisFormatter
24
+
25
+ --format progress # or whatever other formatters you want to use
26
+
27
+ RSpectacles depends on [Redis](http://redis.io) for pubsub and persistence. You
28
+ can quickly get an instance up and running by using your favorite package
29
+ manager:
30
+
31
+ brew install redis
32
+ redis-server
33
+
34
+ Start the server and connect to it in your browser:
35
+
36
+ rspectacles
37
+
38
+ Then run your specs and watch the magic happen!
39
+
40
+ ## The Server
41
+
42
+ The server can be run in standalone mode:
43
+
44
+ rspectacles
45
+
46
+ Or mounted directly on your app:
47
+
48
+ # routes.rb
49
+ mount RSpectacles::App => '/rspectacles'
50
+
51
+ ## Configuration
52
+ If you need to change any settings, the best method is to create a yaml file
53
+ with your settings, and set the ```RSPECTACLES_CONFIG``` environment variable so
54
+ that both the server and formatter can locate the file.
55
+
56
+ For instance:
57
+
58
+ ```sh
59
+ export RSPECTACLES_CONFIG='/path/to/config/rspectacles.yml'
60
+ ```
61
+
62
+ And in ```rspectacles.yml```:
63
+ ```yaml
64
+ sinatra_port: 4567
65
+ redis_uri: 'redis://127.0.0.1:6379/'
66
+ pubsub_channel_name: 'redis-rspec-examples'
67
+ last_run_primary_key: 'redis-rspec-last-run'
68
+ ```
69
+
70
+ ## Realtime Results
71
+
72
+ RSpectacles will attempt to stream spec results into the browser in realtime.
73
+ This optional feature depends on EventMachine, and so will only work on servers
74
+ with EM support. So if you mount RSpectacles on an app that uses
75
+ [thin](http://code.macournoyer.com/thin/) or
76
+ [rainbows](http://rainbows.rubyforge.org/) then
77
+ you should be able to see the realtime results.
78
+
79
+ If you use a server that doesn't support EventMachine - no sweat. You'll still
80
+ be able to see the visualization. You'll just need to refresh your browser
81
+ from time to time.
82
+
83
+ Or you could always spin up an instance in standalone mode, which uses thin by
84
+ default.
85
+
86
+ ## Contributing
87
+
88
+ 1. Fork it
89
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
90
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
91
+ 4. Push to the branch (`git push origin my-new-feature`)
92
+ 5. Create new Pull Request
data/bin/rspectacles CHANGED
@@ -9,4 +9,4 @@ rescue LoadError => e
9
9
  require 'rspectacles/app.rb'
10
10
  end
11
11
 
12
- Thin::Server.start RSpectacles::App, '0.0.0.0', 4567
12
+ Thin::Server.start RSpectacles::App, '0.0.0.0', RSpectacles.config.sinatra_port
@@ -8,7 +8,6 @@ define(['riffle'], function (riffle) {
8
8
  , serverEvents
9
9
  , ajaxEvents
10
10
  , matching
11
- , toArray
12
11
  , toJson
13
12
  , each
14
13
  , stringEvents
@@ -5,11 +5,14 @@ require 'em-hiredis'
5
5
  require 'redis'
6
6
  require 'uri'
7
7
  require 'thin'
8
+ require 'rspectacles/config.rb'
8
9
 
9
10
  module RSpectacles
10
11
  class App < Sinatra::Base
11
12
  require 'rspectacles/app/helpers'
13
+
12
14
  connections = []
15
+ config = RSpectacles.config
13
16
  dir = File.dirname(File.expand_path(__FILE__))
14
17
  set :app_file, __FILE__
15
18
  set :root, dir
@@ -22,7 +25,7 @@ module RSpectacles
22
25
  set :public, "#{dir}/app/public"
23
26
  end
24
27
 
25
- uri = URI.parse 'redis://127.0.0.1:6379/'
28
+ uri = URI.parse config.redis_uri
26
29
  redis = Redis.new host: uri.host, port: uri.port
27
30
 
28
31
  # Routes
@@ -38,14 +41,14 @@ module RSpectacles
38
41
  end
39
42
 
40
43
  get '/last' do
41
- redis.lrange('redis-rspec-last-run', 0, -1).to_json
44
+ redis.lrange(config.last_run_primary_key, 0, -1).to_json
42
45
  end
43
46
 
44
47
  # pubsub and streaming - EventMachine support only
45
48
  EM.next_tick do
46
49
  emredis = EM::Hiredis.connect(uri)
47
50
 
48
- emredis.pubsub.subscribe 'redis-rspec-examples' do |message|
51
+ emredis.pubsub.subscribe config.pubsub_channel_name do |message|
49
52
  connections.each { |out| out << "data: #{message}\n\n" }
50
53
  end
51
54
  end
@@ -0,0 +1,41 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+
4
+ module RSpectacles
5
+ class Config
6
+ def initialize
7
+ user_options = load_user_opts
8
+ @opts = OpenStruct.new defaults.merge(user_options)
9
+ end
10
+
11
+ def defaults
12
+ {
13
+ sinatra_port: 4567,
14
+ pubsub_channel_name: 'redis-rspec-examples',
15
+ last_run_primary_key: 'redis-rspec-last-run',
16
+ redis_uri: 'redis://127.0.0.1:6379/'
17
+ }
18
+ end
19
+
20
+ def load_user_opts
21
+ if ENV['RSPECTACLES_CONFIG'] && ::File.exists?(::File.expand_path(ENV['RSPECTACLES_CONFIG']))
22
+ YAML.load_file(::File.expand_path(ENV['RSPECTACLES_CONFIG']))
23
+ else
24
+ {}
25
+ end
26
+ end
27
+
28
+ def method_missing(method, *args)
29
+ @opts.send method, *args
30
+ end
31
+ end
32
+
33
+ def self.configuration
34
+ @configuration ||= Config.new
35
+ end
36
+
37
+ def self.config
38
+ yield configuration if block_given?
39
+ configuration
40
+ end
41
+ end
@@ -1,4 +1,5 @@
1
1
  require 'rspec/core/formatters/base_formatter'
2
+ require 'rspectacles/config'
2
3
  require 'ostruct'
3
4
  require 'redis'
4
5
 
@@ -8,18 +9,13 @@ module RSpectacles
8
9
 
9
10
  class << self
10
11
  def config
11
- OpenStruct.new({
12
- channel_name: 'redis-rspec-examples',
13
- last_run_key: 'redis-rspec-last-run',
14
- port: 6379,
15
- host: '127.0.0.1',
16
- password: ''
17
- })
12
+ RSpectacles.config
18
13
  end
19
14
  end
20
15
 
21
16
  def initialize(output)
22
- self.redis = Redis.new host: config.host, port: config.port
17
+ uri = config.redis_uri
18
+ self.redis = Redis.new host: uri.host, port: uri.port, password: uri.password
23
19
  end
24
20
 
25
21
  def message(message)
@@ -28,7 +24,7 @@ module RSpectacles
28
24
 
29
25
  def start(example_count)
30
26
  log 'status:start'
31
- redis.del config.last_run_key
27
+ redis.del config.last_run_primary_key
32
28
  end
33
29
 
34
30
  def stop
@@ -60,14 +56,14 @@ module RSpectacles
60
56
  end
61
57
 
62
58
  def log(message)
63
- redis.publish config.channel_name, message
64
- redis.lpush config.last_run_key, message
59
+ redis.publish config.pubsub_channel_name, message
60
+ redis.lpush config.last_run_primary_key, message
65
61
  end
66
62
 
67
63
  def log_formatted(example)
68
64
  message = format_example(example)
69
- redis.publish config.channel_name, message
70
- redis.lpush config.last_run_key, message
65
+ redis.publish config.pubsub_channel_name, message
66
+ redis.lpush config.last_run_primary_key, message
71
67
  end
72
68
 
73
69
  def format_example(example)
@@ -1,3 +1,3 @@
1
1
  module RSpectacles
2
- VERSION='0.0.6'
2
+ VERSION='0.0.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspectacles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Wheeler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-04 00:00:00.000000000 Z
11
+ date: 2013-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -106,6 +106,7 @@ files:
106
106
  - Gemfile
107
107
  - Gemfile.lock
108
108
  - LICENSE
109
+ - README.md
109
110
  - Rakefile
110
111
  - bin/rspectacles
111
112
  - config.ru
@@ -124,6 +125,7 @@ files:
124
125
  - lib/rspectacles/app/public/js/riffle.js
125
126
  - lib/rspectacles/app/public/js/script.js
126
127
  - lib/rspectacles/app/views/index.erb
128
+ - lib/rspectacles/config.rb
127
129
  - lib/rspectacles/redis_formatter.rb
128
130
  - lib/rspectacles/version.rb
129
131
  - rspectacles.gemspec