rspec-console 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzVhMjUwMDdlNmUyM2FjMjRmOWRmMzUzNDE5ZTEwMzI2NDZiNDZlMQ==
4
+ MDFmNGZjYWY1NjQyYjNjZDcwZDg0NzIyOTA1ZjNkMmQ2ZWY5ZGRjYg==
5
5
  data.tar.gz: !binary |-
6
- YWM1MjkwOGIyZDhkZGUxOGExOTQwNWRlMjdkZTE2Y2U5YTJjMmNlNQ==
6
+ OGIxYjNjMTRmYzFiYTIzM2VkMWQ3YmVjMDkwNjFhMWM1N2JmNTQyMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- N2JkOTY1N2EwMDdmMjVmYzliYjJhNWJlNWU5MjY3ZmJhNjQwODU3N2Q3NTAy
10
- YTlhZjk0NTc4NzVmMTE0YmM1YjQwYjZiZDEzNDc2M2RmNDc4YjRhM2Y1MjNi
11
- NTQ1OTQ1ZjM2YzZiNjZhNjU1MDZhYmFmMDhjNTBjNDE4NjhmODM=
9
+ OGM4YThkNzM4MzEwZWFiZmNkMDY5Y2IwODk4YjIyMTViMDQ1NzJhM2JjMTY3
10
+ MjVlZjc3ODgxMDdlOGJhMDFkMDQzNjViNmUzZjNlYjk2ZjM0MGJmZTU1OWEz
11
+ ZmFhZWI2NDdiNDUzY2M1MzcxMWNjZTc2NDFjNmRiMTFjOWU4NjU=
12
12
  data.tar.gz: !binary |-
13
- ZDkzMTZmNjc2NDhiOTY4NWYxNzgyYzRkNjlkZTYzZTQxMjViN2ZmODNhNDE2
14
- YjY4ZTI5YzU2Mjk5Y2FlODA3NTY3NzUxM2M5ZjE3MTY5MTVmZDBhNDg1ZWVk
15
- MTFlMmU3MWRiOGVmNTk2MjQ5ODFjY2FlMWUyMDFiZjI0MzQ1MTE=
13
+ OTI0MDVmYzFlNmIwNGRkMTNiODdlYmY1NzI2NDViNGUzNDg0OWYyYjNlYzQx
14
+ MmYxNzFlYzIyMzU2NmRhZGQwZmZjMjg2MTk2ODZiMzM4MmZiMDhjMzk2NGI4
15
+ YTYwZTcyYjdlZDYxZmUwODk3NGRhY2M4MzEyYjJlMDExOTdmM2U=
data/README.md CHANGED
@@ -11,19 +11,44 @@ Best served chilled with [irb-config](https://github.com/nviennot/irb-config).
11
11
  Usage
12
12
  ------
13
13
 
14
- Install it with:
14
+ ### 1) Install rspec-console with:
15
15
 
16
16
  ```ruby
17
17
  gem 'rspec-console'
18
18
  ```
19
19
 
20
+ ### 2) With Rails, disable cache\_classes so reload! function properly
21
+
22
+ Ensure you turned off Rails's `cache_classes` in the config/environment/test.rb file:
23
+
24
+ ```ruby
25
+ Rails.application.configure do
26
+ # turn off this!
27
+ conig.cache_classes = false
28
+ end
29
+
30
+ ### 3) Launch your console
31
+
32
+ With Rails, launch your console with `rails c test.
33
+
34
+ ```
35
+ ### 4) Launch your tests
36
+
20
37
  If you have [Pry](https://github.com/pry/pry) installed, you will have access to the `rspec` command
21
38
  in your console, which works exactly like the shell command line rspec one.
22
39
 
40
+ If you don't have pry, you can use:
23
41
 
42
+ ```ruby
43
+ RSpecConsole.run 'spec/integration/closing_brand_action_spec.rb:33' '--format=doc'
24
44
  ```
25
- pafy@bisou ~/prj/sniper [master●] % rails c
26
- ~/prj/crowdtap/sniper (development) > rspec spec/integration/closing_brand_action_spec.rb:33 --format=doc
45
+
46
+ Example
47
+ -------
48
+
49
+ ```
50
+ pafy@bisou ~/prj/sniper [master●] % rails c test
51
+ ~/prj/crowdtap/sniper (test) > rspec spec/integration/closing_brand_action_spec.rb:33 --format=doc
27
52
  Run options: include {:locations=>{"./spec/integration/closing_brand_action_spec.rb"=>[33]}}
28
53
 
29
54
  Sniper
@@ -32,13 +57,7 @@ Sniper
32
57
 
33
58
  Finished in 0.12654 seconds
34
59
  1 example, 0 failures
35
- ~/prj/crowdtap/sniper (development) >
36
- ```
37
-
38
- If you don't have pry, you can use:
39
-
40
- ```ruby
41
- RSpecConsole.run 'spec/integration/closing_brand_action_spec.rb:33' '--format=doc'
60
+ ~/prj/crowdtap/sniper (test) >
42
61
  ```
43
62
 
44
63
  TODO
@@ -1,40 +1,34 @@
1
1
  class RSpecConsole::Runner
2
- def self.reset(args)
3
- require 'rspec/core'
2
+ class << self
3
+ def reset(args)
4
+ require 'rspec/core'
4
5
 
5
- if Gem.loaded_specs['rspec-core'].version < Gem::Version.new('2.9.10')
6
- raise 'Please use RSpec 2.9.10 or later'
7
- end
6
+ if Gem.loaded_specs['rspec-core'].version < Gem::Version.new('2.9.10')
7
+ raise 'Please use RSpec 2.9.10 or later'
8
+ end
8
9
 
9
- ::RSpec::Core::Runner.disable_autorun!
10
- ::RSpec::Core::Configuration.class_eval { define_method(:command) { 'rspec' } }
11
- ::RSpec.reset
10
+ ::RSpec::Core::Runner.disable_autorun!
11
+ ::RSpec::Core::Configuration.class_eval { define_method(:command) { 'rspec' } }
12
+ ::RSpec.reset
12
13
 
13
- self.config_cache.cache do
14
- ::RSpec.configure do |config|
15
- config.output_stream = STDOUT
16
- config.color_enabled = true
17
- end
14
+ config_cache.cache do
15
+ ::RSpec.configure do |config|
16
+ config.output_stream = STDOUT
17
+ config.color_enabled = true
18
+ end
18
19
 
19
- require "./spec/spec_helper"
20
+ require "./spec/spec_helper"
21
+ end
20
22
  end
21
- end
22
23
 
23
- def self._run(args)
24
- reset(args)
25
- ::RSpec::Core::CommandLine.new(args).run(STDERR, STDOUT)
26
- end
27
-
28
- def self.run(args)
29
- if defined?(Rails)
30
- require 'rails-env-switcher'
31
- RailsEnvSwitcher.with_env('test', :reload => true) { _run(args) }
32
- else
33
- _run(args)
24
+ def run(args)
25
+ RSpecConsole.hooks.each(&:call)
26
+ reset(args)
27
+ ::RSpec::Core::CommandLine.new(args).run(STDERR, STDOUT)
34
28
  end
35
- end
36
29
 
37
- def self.config_cache
38
- @config_cache ||= RSpecConsole::ConfigCache.new
30
+ def config_cache
31
+ @config_cache ||= RSpecConsole::ConfigCache.new
32
+ end
39
33
  end
40
34
  end
@@ -1,3 +1,3 @@
1
1
  module RSpecConsole
2
- VERSION = '0.2.8'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/rspec-console.rb CHANGED
@@ -3,9 +3,46 @@ module RSpecConsole
3
3
  autoload :Runner, 'rspec-console/runner'
4
4
  autoload :Pry, 'rspec-console/pry'
5
5
 
6
+ class << self; attr_accessor :hooks; end
7
+ self.hooks = []
8
+
6
9
  def self.run(*args)
7
10
  Runner.run(args)
8
11
  end
9
12
 
13
+ def self.register_hook(&hook)
14
+ self.hooks << hook
15
+ end
16
+
10
17
  Pry.setup if defined?(::Pry)
18
+
19
+ # We only want the test env
20
+ register_hook do
21
+ if defined?(Rails) && !Rails.env.test?
22
+ raise "Rails env must be set as test (use `rails console test` to launch the console)."
23
+ end
24
+ end
25
+
26
+ # Emit warning when reload cannot be called, or call reload!
27
+ register_hook do
28
+ if defined?(Rails)
29
+ if Rails.application.config.cache_classes
30
+ STDERR.puts <<-MSG
31
+ [WARNING]
32
+ Rails's cache_classes must be turned off.
33
+ Turn off in config/environments/test.rb:
34
+
35
+ Rails.application.configure do
36
+ conig.cache_classes = false
37
+ end
38
+ MSG
39
+ else
40
+ ActionDispatch::Reloader.cleanup!
41
+ ActionDispatch::Reloader.prepare!
42
+ end
43
+ end
44
+ end
45
+
46
+ # Reloading FactoryGirl if necessary
47
+ register_hook { FactoryGirl.reload if defined?(FactoryGirl) }
11
48
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Viennot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-19 00:00:00.000000000 Z
11
+ date: 2014-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- type: :runtime
15
- prerelease: false
16
- name: rails-env-switcher
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  type: :runtime
29
15
  prerelease: false
@@ -59,11 +45,11 @@ executables: []
59
45
  extensions: []
60
46
  extra_rdoc_files: []
61
47
  files:
62
- - lib/rspec-console.rb
63
48
  - lib/rspec-console/config_cache.rb
64
- - lib/rspec-console/runner.rb
65
49
  - lib/rspec-console/pry.rb
50
+ - lib/rspec-console/runner.rb
66
51
  - lib/rspec-console/version.rb
52
+ - lib/rspec-console.rb
67
53
  - README.md
68
54
  homepage: http://github.com/nviennot/rspec-console
69
55
  licenses: []