rspec_runner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3cf290c42a9fc6ea639128fbce4c50aca3f623c
4
+ data.tar.gz: 734d78fc95d9f9559f2598c2ab3fee10225ca2ae
5
+ SHA512:
6
+ metadata.gz: f67dfbfe26d7c13ec41988cdf1634e09dd9f561014512a5fa891735f46090a94a75bc63462712816ac63adfb1575da7ede43157789a1dbf3cc36fc032170b97f
7
+ data.tar.gz: 8b3c62d639b760e16ae057b4e71416d9199d6fb5b7ab37165fbcf55a98ba2c0156cba15622cd4838db95c2c256a218889c85c8e205e9d0a855d8a9acc93087de
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec_runner.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 exAspArk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # RspecRunner
2
+
3
+ ## Usage
4
+
5
+ Run monitor:
6
+
7
+ $ bundle exec rspec_runner monitor
8
+
9
+ It runs `monitor`, which requires all dependencies and shows test results with RSpec.
10
+ It also tracks file changes and automatically reloads all dependencies if necessary.
11
+
12
+ Run your test:
13
+
14
+ $ bundle exec rspec_runner spec/models/account_spec.rb:3
15
+
16
+ It connects to `monitor` through DRb and executes tests.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'rspec_runner'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec_runner. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rspec_runner ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ cmd = ARGV[0]
4
+
5
+ case cmd
6
+ when 'monitor'.freeze
7
+ require 'rspec_runner/monitor'
8
+ RspecRunner::Monitor.run
9
+ when 'start'.freeze
10
+ require 'rspec_runner/server'
11
+ RspecRunner::Server.run
12
+ else
13
+ require 'rspec_runner/client'
14
+ RspecRunner::Client.execute(cmd)
15
+ end
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ require 'drb/drb'
2
+ require 'rspec_runner/configuration'
3
+
4
+ module RspecRunner
5
+ class Client
6
+ class << self
7
+ def execute(*args)
8
+ DRb.start_service
9
+ runner = DRbObject.new_with_uri(RspecRunner.configuration.uri)
10
+
11
+ try_count = 0
12
+ print 'Running tests... '
13
+ while try_count <= RspecRunner.configuration.client_timeout
14
+ begin
15
+ runner.execute(*args)
16
+ puts 'done!'
17
+ return true
18
+ rescue DRb::DRbConnError
19
+ try_count += 1
20
+ sleep(1)
21
+ end
22
+ end
23
+
24
+ puts 'Server is down :('
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ module RspecRunner
2
+ class Configuration
3
+ attr_accessor :uri, :client_timeout, :watch_directories, :watch_pattern
4
+
5
+ def initialize
6
+ @uri = 'druby://localhost:8787'.freeze
7
+ @client_timeout = 10 # seconds
8
+ @watch_directories = ["#{Dir.pwd}/app", "#{Dir.pwd}/lib"]
9
+ @watch_pattern = /\.rb$/
10
+ end
11
+ end
12
+
13
+ def self.configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def self.configure
18
+ yield(configuration)
19
+ end
20
+ end
@@ -0,0 +1,51 @@
1
+ require 'open3'
2
+ require 'rspec_runner/watcher'
3
+
4
+ module RspecRunner
5
+ class Monitor
6
+ CMD = 'bundle exec rspec_runner start'.freeze
7
+
8
+ class << self
9
+ def run
10
+ start
11
+
12
+ at_exit { die }
13
+
14
+ watcher_thread = Watcher.run do |changes|
15
+ puts 'Restarting...'
16
+ restart
17
+ end
18
+
19
+ watcher_thread.join
20
+ sleep 10_000 while true # :(
21
+ end
22
+
23
+ private
24
+
25
+ def start
26
+ @pid = fork { exec(CMD) }
27
+ Process.detach(@pid) # so if the child exits, it dies
28
+ end
29
+
30
+ def stop
31
+ if @pid && @pid != 0
32
+ send_signal('KILL') # TODO: try to kill without -9
33
+ end
34
+ end
35
+
36
+ def send_signal(signal)
37
+ Process.kill(signal, @pid)
38
+ end
39
+
40
+ def die
41
+ stop
42
+ exit 0
43
+ end
44
+
45
+ def restart
46
+ stop
47
+ start
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,55 @@
1
+ require 'drb/drb'
2
+ require 'rspec_runner/configuration'
3
+
4
+ module RspecRunner
5
+ class Server
6
+ class << self
7
+ def run
8
+ puts 'Loading dependencies...'
9
+
10
+ $LOAD_PATH.unshift File.expand_path("#{Dir.pwd}/spec")
11
+ require 'rspec'
12
+ require 'spec_helper.rb'
13
+
14
+ DRb.start_service(RspecRunner.configuration.uri, self)
15
+ puts 'Server started!'
16
+
17
+ DRb.thread.join
18
+ end
19
+
20
+ def execute(path)
21
+ RSpec.configuration.start_time = Time.now
22
+ RSpec::Core::Runner.run(filepaths(path))
23
+ ensure
24
+ reset_rspec!
25
+ end
26
+
27
+ private
28
+
29
+ def filepaths(path)
30
+ multiple_files?(path) ? Dir.glob(path) : [path]
31
+ end
32
+
33
+ def multiple_files?(path)
34
+ path.include?('*'.freeze)
35
+ end
36
+
37
+ def reset_rspec!
38
+ world = RSpec.world
39
+ configuration = RSpec.configuration
40
+
41
+ world.reset
42
+ world.filtered_examples.clear
43
+ world.instance_variable_set(:@example_group_counts_by_spec_file, Hash.new(0))
44
+ configuration.reset
45
+ configuration.reset_filters if configuration.respond_to?(:reset_filters)
46
+ configuration.files_to_run = []
47
+ configuration.files_or_directories_to_run = []
48
+
49
+ if configuration.respond_to?(:loaded_spec_files) && set = configuration.loaded_spec_files
50
+ set.each { |k| set.delete(k) }
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module RspecRunner
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'listen'
2
+ require 'rspec_runner/configuration'
3
+
4
+ module RspecRunner
5
+ class Watcher
6
+ class << self
7
+ def run(&block)
8
+ if @thread then
9
+ raise RuntimeError, "already started"
10
+ end
11
+
12
+ @thread = Thread.new do
13
+ @listener = Listen.to(
14
+ *RspecRunner.configuration.watch_directories,
15
+ only: RspecRunner.configuration.watch_pattern,
16
+ wait_for_delay: 1
17
+ ) do |modified, added, removed|
18
+ if((modified.size + added.size + removed.size) > 0)
19
+ block.call(modified: modified, added: added, removed: removed)
20
+ end
21
+ end
22
+ @listener.start
23
+ puts 'Watcher started!'
24
+ end
25
+
26
+ sleep(0.1) until @listener
27
+
28
+ at_exit { stop }
29
+
30
+ @thread
31
+ end
32
+
33
+ private
34
+
35
+ def stop
36
+ @thread.wakeup rescue ThreadError
37
+ begin
38
+ @listener.stop
39
+ rescue => e
40
+ puts "#{e.class}: #{e.message} stopping listener"
41
+ end
42
+ @thread.kill rescue ThreadError
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec_runner/version'
2
+ require 'rspec_runner/configuration'
3
+
4
+ module RspecRunner
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec_runner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec_runner"
8
+ spec.version = RspecRunner::VERSION
9
+ spec.authors = ["exAspArk"]
10
+ spec.email = ["exaspark@gmail.com"]
11
+
12
+ spec.summary = %q{Application preloader for running RSpec}
13
+ spec.description = %q{Works even with non-Rails apps}
14
+ spec.homepage = "https://github.com/exAspArk/rspec_runner"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'bin'
19
+ spec.require_paths = ["lib"]
20
+ spec.executables << 'rspec_runner'
21
+
22
+ spec.add_runtime_dependency 'rspec', '~> 3.0'
23
+ spec.add_runtime_dependency 'listen', '~> 3.0'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_runner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - exAspArk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: listen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Works even with non-Rails apps
70
+ email:
71
+ - exaspark@gmail.com
72
+ executables:
73
+ - rspec_runner
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/rspec_runner
84
+ - bin/setup
85
+ - lib/rspec_runner.rb
86
+ - lib/rspec_runner/client.rb
87
+ - lib/rspec_runner/configuration.rb
88
+ - lib/rspec_runner/monitor.rb
89
+ - lib/rspec_runner/server.rb
90
+ - lib/rspec_runner/version.rb
91
+ - lib/rspec_runner/watcher.rb
92
+ - rspec_runner.gemspec
93
+ homepage: https://github.com/exAspArk/rspec_runner
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Application preloader for running RSpec
117
+ test_files: []
118
+ has_rdoc: