rspec-console 0.1

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.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ RSpec Console
2
+ =============
3
+
4
+ RSpec Console allows you to run your RSpec tests in a Rails console.
5
+ Best served chilled with [irb-config](https://github.com/nviennot/irb-config).
6
+
7
+ ### Watch the screencast
8
+
9
+ [![Watch the screencast!](https://s3.amazonaws.com/velvetpulse/screencasts/irb-config-screencast.jpg)](http://velvetpulse.com/2012/11/19/improve-your-ruby-workflow-by-integrating-vim-tmux-pry/)
10
+
11
+ Usage
12
+ ------
13
+
14
+ Install it with:
15
+
16
+ ```ruby
17
+ gem 'rspec-console'
18
+ ```
19
+
20
+ If you have [Pry](https://github.com/pry/pry) installed, you will have access to the `rspec` command
21
+ in your console, which works exactly like the shell command line rspec one.
22
+
23
+
24
+ ```
25
+ pafy@bisou ~/prj/sniper [master●] % rails c
26
+ ~/prj/crowdtap/sniper (development) > rspec spec/integration/closing_brand_action_spec.rb:33 --format=doc
27
+ Run options: include {:locations=>{"./spec/integration/closing_brand_action_spec.rb"=>[33]}}
28
+
29
+ Sniper
30
+ when reaching the maximum number of participants
31
+ no longer targets this brand action on members
32
+
33
+ Finished in 0.12654 seconds
34
+ 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'
42
+ ```
43
+
44
+ TODO
45
+ ----
46
+
47
+ * Testing
48
+
49
+ License
50
+ -------
51
+
52
+ MIT License
@@ -0,0 +1,71 @@
1
+ class RSpecConsole::ConfigCache
2
+ # We have to reset the RSpec.configuration, because it contains a lot of
3
+ # information related to the current test (what's running, what are the
4
+ # different test results, etc).
5
+ #
6
+ # RSpec.configuration gets also loaded with a bunch of stuff from the
7
+ # 'spec/spec_helper.rb' file. Often that instance is extended with other
8
+ # modules (FactoryGirl, Mocha,...) and we don't want to replace requires with
9
+ # load all around the place.
10
+ #
11
+ # Instead, we cache whatever is done to RSpec.configuration during the
12
+ # first invokration of require('spec_helper').
13
+ # This is done by interposing the Proxy class on top of RSpec.configuration.
14
+ #
15
+ attr_accessor :proxy, :recorded_config, :shared_examples_groups
16
+
17
+ def initialize
18
+ ::RSpec.instance_eval do
19
+ def self.configuration=(value)
20
+ @configuration = value
21
+ end
22
+ end
23
+ end
24
+
25
+ def cache
26
+ if self.proxy
27
+ # replay
28
+ ::RSpec.configure do |config|
29
+ self.recorded_config.each do |msg|
30
+ config.send(msg[:method], *msg[:args], &msg[:block])
31
+ end
32
+ end
33
+ ::RSpec.world.shared_example_groups.merge!(self.shared_examples_groups)
34
+
35
+ else
36
+ # record
37
+ real_config = ::RSpec.configuration
38
+ self.recorded_config = []
39
+ self.proxy = Proxy.new(self.recorded_config, real_config)
40
+ ::RSpec.configuration = self.proxy
41
+ yield
42
+ ::RSpec.configuration = real_config
43
+ self.shared_examples_groups = ::RSpec.world.shared_example_groups.dup
44
+
45
+ # rspec-rails/lib/rspec/rails/view_rendering.rb add methods on the
46
+ # configuration singleton. Need advice to copy them without going down
47
+ # the road with object2module.
48
+ end
49
+
50
+ # Well, instead of copying them, we redirect them to the configuration
51
+ # proxy. Looks like it good enough.
52
+ proxy = self.proxy
53
+ ::RSpec.configuration.define_singleton_method(:method_missing) do |method, *args, &block|
54
+ proxy.send(method, *args, &block)
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ class Proxy < Struct.new(:output, :target)
61
+ [:include, :extend].each do |method|
62
+ define_method(method) do |*args|
63
+ method_missing(method, *args)
64
+ end
65
+ end
66
+
67
+ def method_missing(method, *args, &block)
68
+ self.output << {:method => method, :args => args, :block => block}
69
+ self.target.send(method, *args, &block)
70
+ end
71
+ end
@@ -0,0 +1,12 @@
1
+ module RSpecConsole::Pry
2
+ def self.setup
3
+ ::Pry::CommandSet.new do
4
+ create_command "rspec", "Works pretty much like the regular rspec command" do
5
+ group "Testing"
6
+ def process(*args)
7
+ RSpecConsole::Runner.run(args)
8
+ end
9
+ end
10
+ end.tap { |cmd| ::Pry::Commands.import cmd }
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ class RSpecConsole::Runner
2
+ def self.run(args)
3
+ require 'rails-env-switcher'
4
+
5
+ RailsEnvSwitcher.with_env('test', :reload => true) do
6
+ require 'rspec'
7
+
8
+ if Gem.loaded_specs['rspec'].version < Gem::Version.new('2.9.10')
9
+ raise 'Please use RSpec 2.9.10 or later'
10
+ end
11
+
12
+ ::RSpec::Core::Runner.disable_autorun!
13
+ ::RSpec::Core::Configuration.class_eval { define_method(:command) { 'rspec' } }
14
+ ::RSpec.reset
15
+
16
+ self.config_cache.cache do
17
+ ::RSpec.configure do |config|
18
+ config.output_stream = STDOUT
19
+ config.color_enabled = true
20
+ end
21
+
22
+ require "./spec/spec_helper"
23
+ end
24
+
25
+ ::RSpec::Core::CommandLine.new(args).run(STDERR, STDOUT)
26
+ end
27
+ end
28
+
29
+ def self.config_cache
30
+ @config_cache ||= RSpecConsole::ConfigCache.new
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module RSpecConsole
2
+ VERSION = '0.1'
3
+ end
@@ -0,0 +1,11 @@
1
+ module RSpecConsole
2
+ autoload :ConfigCache, 'rspec-console/config_cache'
3
+ autoload :Runner, 'rspec-console/runner'
4
+ autoload :Pry, 'rspec-console/pry'
5
+
6
+ def self.run(*args)
7
+ Runner.run(args)
8
+ end
9
+
10
+ Pry.setup if defined?(::Pry)
11
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-console
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nicolas Viennot
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.9.10
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.9.10
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails-env-switcher
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Run RSpec tests in your console
47
+ email:
48
+ - nicolas@viennot.biz
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/rspec-console/config_cache.rb
54
+ - lib/rspec-console/version.rb
55
+ - lib/rspec-console/pry.rb
56
+ - lib/rspec-console/runner.rb
57
+ - lib/rspec-console.rb
58
+ - README.md
59
+ homepage: http://github.com/nviennot/rspec-console
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.24
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Run RSpec tests in your console
83
+ test_files: []
84
+ has_rdoc: false