rspec_candy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.gitignore +8 -0
  2. data/README.md +7 -0
  3. data/Rakefile +18 -0
  4. data/lib/rspec_candy/helpers/disposable_copy.rb +16 -0
  5. data/lib/rspec_candy/helpers/it_should_act_like.rb +39 -0
  6. data/lib/rspec_candy/helpers/new_with_stubs.rb +16 -0
  7. data/lib/rspec_candy/helpers/rails/create_without_callbacks.rb +25 -0
  8. data/lib/rspec_candy/helpers/rails/it_should_run_callbacks.rb +111 -0
  9. data/lib/rspec_candy/helpers/rails/prevent_storage.rb +20 -0
  10. data/lib/rspec_candy/helpers/should_receive_and_execute.rb +38 -0
  11. data/lib/rspec_candy/helpers/should_receive_and_return.rb +17 -0
  12. data/lib/rspec_candy/helpers/should_receive_chain.rb +43 -0
  13. data/lib/rspec_candy/helpers/stub_any_instance.rb +25 -0
  14. data/lib/rspec_candy/helpers/stub_existing.rb +20 -0
  15. data/lib/rspec_candy/switcher.rb +44 -0
  16. data/lib/rspec_candy/version.rb +3 -0
  17. data/lib/rspec_candy.rb +16 -0
  18. data/rspec_candy.gemspec +19 -0
  19. data/spec/rspec1/Gemfile +13 -0
  20. data/spec/rspec1/Rakefile +11 -0
  21. data/spec/rspec1/app_root/config/boot.rb +114 -0
  22. data/spec/rspec1/app_root/config/database.yml +21 -0
  23. data/spec/rspec1/app_root/config/environment.rb +14 -0
  24. data/spec/rspec1/app_root/config/environments/in_memory.rb +0 -0
  25. data/spec/rspec1/app_root/config/environments/mysql.rb +0 -0
  26. data/spec/rspec1/app_root/config/environments/postgresql.rb +0 -0
  27. data/spec/rspec1/app_root/config/environments/sqlite.rb +0 -0
  28. data/spec/rspec1/app_root/config/environments/sqlite3.rb +0 -0
  29. data/spec/rspec1/app_root/config/initializers/state_machine.rb +1 -0
  30. data/spec/rspec1/app_root/config/routes.rb +4 -0
  31. data/spec/rspec1/app_root/log/.gitignore +1 -0
  32. data/spec/rspec1/rcov.opts +2 -0
  33. data/spec/rspec1/spec.opts +4 -0
  34. data/spec/rspec1/spec_helper.rb +24 -0
  35. data/spec/rspec2/.rspec +2 -0
  36. data/spec/rspec2/Gemfile +13 -0
  37. data/spec/rspec2/Rakefile +11 -0
  38. data/spec/rspec2/app_root/.gitignore +4 -0
  39. data/spec/rspec2/app_root/config/application.rb +32 -0
  40. data/spec/rspec2/app_root/config/boot.rb +13 -0
  41. data/spec/rspec2/app_root/config/database.yml +21 -0
  42. data/spec/rspec2/app_root/config/environment.rb +5 -0
  43. data/spec/rspec2/app_root/config/environments/in_memory.rb +0 -0
  44. data/spec/rspec2/app_root/config/environments/mysql.rb +0 -0
  45. data/spec/rspec2/app_root/config/environments/postgresql.rb +0 -0
  46. data/spec/rspec2/app_root/config/environments/sqlite.rb +0 -0
  47. data/spec/rspec2/app_root/config/environments/sqlite3.rb +0 -0
  48. data/spec/rspec2/app_root/config/environments/test.rb +35 -0
  49. data/spec/rspec2/app_root/config/initializers/backtrace_silencers.rb +7 -0
  50. data/spec/rspec2/app_root/config/initializers/inflections.rb +10 -0
  51. data/spec/rspec2/app_root/config/initializers/mime_types.rb +5 -0
  52. data/spec/rspec2/app_root/config/initializers/secret_token.rb +7 -0
  53. data/spec/rspec2/app_root/config/initializers/session_store.rb +8 -0
  54. data/spec/rspec2/app_root/config/initializers/state_machine.rb +1 -0
  55. data/spec/rspec2/app_root/config/locales/en.yml +5 -0
  56. data/spec/rspec2/app_root/config/routes.rb +58 -0
  57. data/spec/rspec2/app_root/log/.gitkeep +0 -0
  58. data/spec/rspec2/rcov.opts +2 -0
  59. data/spec/rspec2/spec_helper.rb +25 -0
  60. data/spec/shared/app_root/app/controllers/application_controller.rb +2 -0
  61. data/spec/shared/app_root/app/models/model.rb +19 -0
  62. data/spec/shared/app_root/app/models/state_machine_model.rb +30 -0
  63. data/spec/shared/app_root/config/initializers/state_machine.rb +1 -0
  64. data/spec/shared/app_root/db/migrate/001_create_model.rb +13 -0
  65. data/spec/shared/app_root/db/migrate/002_create_state_machine_model.rb +13 -0
  66. data/spec/shared/rspec_candy/helpers/disposable_copy_spec.rb +45 -0
  67. data/spec/shared/rspec_candy/helpers/it_should_act_like_spec.rb +139 -0
  68. data/spec/shared/rspec_candy/helpers/new_with_stubs_spec.rb +41 -0
  69. data/spec/shared/rspec_candy/helpers/rails/create_without_callbacks_spec.rb +41 -0
  70. data/spec/shared/rspec_candy/helpers/rails/it_should_run_callbacks_spec.rb +142 -0
  71. data/spec/shared/rspec_candy/helpers/rails/prevent_storage_spec.rb +85 -0
  72. data/spec/shared/rspec_candy/helpers/should_receive_and_execute_spec.rb +32 -0
  73. data/spec/shared/rspec_candy/helpers/should_receive_and_return_spec.rb +30 -0
  74. data/spec/shared/rspec_candy/helpers/should_receive_chain_spec.rb +99 -0
  75. data/spec/shared/rspec_candy/helpers/stub_any_instance_spec.rb +32 -0
  76. data/spec/shared/rspec_candy/helpers/stub_existing_spec.rb +27 -0
  77. data/spec/shared/support/matchers/pass_as_describe_block.rb +32 -0
  78. data/spec/shared/support/matchers/pass_as_example.rb +30 -0
  79. data/template/spec_candy.rails2.rb +171 -0
  80. data/template/spec_candy.rails3.rb +175 -0
  81. metadata +159 -0
@@ -0,0 +1,3 @@
1
+ module RSpecCandy
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'rspec_candy/version'
2
+ require 'rspec_candy/switcher'
3
+ require 'rspec_candy/helpers/disposable_copy'
4
+ require 'rspec_candy/helpers/it_should_act_like'
5
+ require 'rspec_candy/helpers/new_with_stubs'
6
+ require 'rspec_candy/helpers/should_receive_and_execute'
7
+ require 'rspec_candy/helpers/should_receive_and_return'
8
+ require 'rspec_candy/helpers/should_receive_chain'
9
+ require 'rspec_candy/helpers/stub_any_instance'
10
+ require 'rspec_candy/helpers/stub_existing'
11
+
12
+ if RSpecCandy::Switcher.rails_loaded?
13
+ require 'rspec_candy/helpers/rails/create_without_callbacks'
14
+ require 'rspec_candy/helpers/rails/it_should_run_callbacks'
15
+ require 'rspec_candy/helpers/rails/prevent_storage'
16
+ end
@@ -0,0 +1,19 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "rspec_candy/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'rspec_candy'
6
+ s.version = RSpecCandy::VERSION
7
+ s.authors = ["Henning Koch", "Tobias Kraze"]
8
+ s.email = 'henning.koch@makandra.de'
9
+ s.homepage = 'https://github.com/makandra/rspec_candy'
10
+ s.summary = 'RSpec helpers and matchers we use in our daily work at makandra. '
11
+ s.description = s.summary
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_dependency('rspec')
19
+ end
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'sqlite3'
4
+ gem 'rails', '~>2'
5
+ gem 'rspec', '~>1'
6
+ gem 'rspec-rails', '~>1'
7
+ gem 'ruby-debug'
8
+ gem 'rspec_candy', :path => '../..'
9
+
10
+ group :state_machine do
11
+ gem 'state_machine'
12
+ end
13
+
@@ -0,0 +1,11 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc 'Default: Run all specs for a specific rails version.'
5
+ task :default => :spec
6
+
7
+ desc "Run all specs for a specific rails version"
8
+ Spec::Rake::SpecTask.new() do |t|
9
+ t.spec_opts = ['--options', "\"spec.opts\""]
10
+ t.spec_files = defined?(SPEC) ? SPEC : FileList['**/*_spec.rb', '../shared/**/*_spec.rb']
11
+ end
@@ -0,0 +1,114 @@
1
+ # Allow customization of the rails framework path
2
+ RAILS_FRAMEWORK_ROOT = (ENV['RAILS_FRAMEWORK_ROOT'] || "#{File.dirname(__FILE__)}/../../../../../../vendor/rails") unless defined?(RAILS_FRAMEWORK_ROOT)
3
+
4
+ # Don't change this file!
5
+ # Configure your app in config/environment.rb and config/environments/*.rb
6
+
7
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
8
+
9
+ module Rails
10
+ class << self
11
+ def boot!
12
+ unless booted?
13
+ preinitialize
14
+ pick_boot.run
15
+ end
16
+ end
17
+
18
+ def booted?
19
+ defined? Rails::Initializer
20
+ end
21
+
22
+ def pick_boot
23
+ (vendor_rails? ? VendorBoot : GemBoot).new
24
+ end
25
+
26
+ def vendor_rails?
27
+ File.exist?(RAILS_FRAMEWORK_ROOT)
28
+ end
29
+
30
+ def preinitialize
31
+ load(preinitializer_path) if File.exist?(preinitializer_path)
32
+ end
33
+
34
+ def preinitializer_path
35
+ "#{RAILS_ROOT}/config/preinitializer.rb"
36
+ end
37
+ end
38
+
39
+ class Boot
40
+ def run
41
+ load_initializer
42
+ Rails::Initializer.run(:set_load_path)
43
+ end
44
+ end
45
+
46
+ class VendorBoot < Boot
47
+ def load_initializer
48
+ require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
49
+ Rails::Initializer.run(:install_gem_spec_stubs)
50
+ end
51
+ end
52
+
53
+ class GemBoot < Boot
54
+ def load_initializer
55
+ self.class.load_rubygems
56
+ load_rails_gem
57
+ require 'initializer'
58
+ end
59
+
60
+ def load_rails_gem
61
+ if version = self.class.gem_version
62
+ gem 'rails', version
63
+ else
64
+ gem 'rails'
65
+ end
66
+ rescue Gem::LoadError => load_error
67
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
68
+ exit 1
69
+ end
70
+
71
+ class << self
72
+ def rubygems_version
73
+ Gem::RubyGemsVersion rescue nil
74
+ end
75
+
76
+ def gem_version
77
+ if defined? RAILS_GEM_VERSION
78
+ RAILS_GEM_VERSION
79
+ elsif ENV.include?('RAILS_GEM_VERSION')
80
+ ENV['RAILS_GEM_VERSION']
81
+ else
82
+ parse_gem_version(read_environment_rb)
83
+ end
84
+ end
85
+
86
+ def load_rubygems
87
+ require 'rubygems'
88
+ min_version = '1.1.1'
89
+ unless rubygems_version >= min_version
90
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
91
+ exit 1
92
+ end
93
+
94
+ rescue LoadError
95
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
96
+ exit 1
97
+ end
98
+
99
+ def parse_gem_version(text)
100
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
101
+ end
102
+
103
+ private
104
+ def read_environment_rb
105
+ environment_rb = "#{RAILS_ROOT}/config/environment.rb"
106
+ environment_rb = "#{HELPER_RAILS_ROOT}/config/environment.rb" unless File.exists?(environment_rb)
107
+ File.read(environment_rb)
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ # All that for this:
114
+ Rails.boot!
@@ -0,0 +1,21 @@
1
+ in_memory:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+ verbosity: quiet
5
+ sqlite:
6
+ adapter: sqlite
7
+ dbfile: plugin_test.sqlite.db
8
+ sqlite3:
9
+ adapter: sqlite3
10
+ dbfile: plugin_test.sqlite3.db
11
+ postgresql:
12
+ adapter: postgresql
13
+ username: postgres
14
+ password: postgres
15
+ database: plugin_test
16
+ mysql:
17
+ adapter: mysql
18
+ host: localhost
19
+ username: root
20
+ password:
21
+ database: plugin_test
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), 'boot')
2
+
3
+ Rails::Initializer.run do |config|
4
+ config.cache_classes = false
5
+ config.whiny_nils = true
6
+ config.action_controller.session = { :key => "_myapp_session", :secret => "gwirofjweroijger8924rt2zfwehfuiwehb1378rifowenfoqwphf23" }
7
+ config.plugin_locators.unshift(
8
+ Class.new(Rails::Plugin::Locator) do
9
+ def plugins
10
+ [Rails::Plugin.new(File.expand_path('.'))]
11
+ end
12
+ end
13
+ ) unless defined?(PluginTestHelper::PluginLocator)
14
+ end
File without changes
@@ -0,0 +1 @@
1
+ Bundler.require(:state_machine) if ENV['REQUIRE_STATE_MACHINE'] == 'true'
@@ -0,0 +1,4 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.connect ':controller/:action/:id'
3
+ map.connect ':controller/:action/:id.:format'
4
+ end
@@ -0,0 +1 @@
1
+ *.log
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,24 @@
1
+ $: << File.join(File.dirname(__FILE__), "/../lib" )
2
+
3
+ # Set the default environment to sqlite3's in_memory database
4
+ ENV['RAILS_ENV'] ||= 'in_memory'
5
+
6
+ # Load the Rails environment and testing framework
7
+ require "#{File.dirname(__FILE__)}/app_root/config/environment"
8
+ require 'spec/rails'
9
+
10
+ # Load dependencies
11
+ require 'rspec_candy'
12
+
13
+ # Require support code
14
+ Dir["../shared/support/**/*.rb"].each {|f| require f}
15
+
16
+ # Run the migrations
17
+ print "\033[30m" # dark gray text
18
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
19
+ print "\033[0m"
20
+
21
+ Spec::Runner.configure do |config|
22
+ config.use_transactional_fixtures = true
23
+ config.use_instantiated_fixtures = false
24
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'sqlite3'
4
+ gem 'rails', '~>3'
5
+ gem 'rspec', '~>2'
6
+ gem 'rspec-rails', '~>2'
7
+ gem 'ruby-debug'
8
+ gem 'rspec_candy', :path => '../..'
9
+
10
+
11
+ group :state_machine do
12
+ gem 'state_machine'
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: Run all specs for a specific rails version.'
5
+ task :default => :spec
6
+
7
+ desc "Run all specs for a specific rails version"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.verbose = false
10
+ t.pattern = defined?(SPEC) ? SPEC : ['**/*_spec.rb', '../shared/**/*_spec.rb']
11
+ end
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # If you have a Gemfile, require the gems listed there, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
8
+
9
+
10
+ module HasDefaultSpecApp
11
+ class Application < Rails::Application
12
+ config.encoding = "utf-8"
13
+
14
+ config.cache_classes = true
15
+ config.whiny_nils = true
16
+
17
+ config.consider_all_requests_local = true
18
+ config.action_controller.perform_caching = false
19
+
20
+ config.action_dispatch.show_exceptions = false
21
+
22
+ config.action_controller.allow_forgery_protection = false
23
+
24
+ config.action_mailer.delivery_method = :test
25
+
26
+ config.active_support.deprecation = :stderr
27
+
28
+ config.root = File.expand_path('../..', __FILE__)
29
+
30
+ # railties.plugins << Rails::Plugin.new(File.expand_path('../../../../..', __FILE__))
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
5
+ begin
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
7
+ require 'bundler'
8
+ Bundler.setup
9
+ rescue Bundler::GemNotFound => e
10
+ STDERR.puts e.message
11
+ STDERR.puts "Try running `bundle install`."
12
+ exit!
13
+ end if File.exist?(gemfile)
@@ -0,0 +1,21 @@
1
+ in_memory:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+ verbosity: quiet
5
+ sqlite:
6
+ adapter: sqlite
7
+ dbfile: plugin_test.sqlite.db
8
+ sqlite3:
9
+ adapter: sqlite3
10
+ dbfile: plugin_test.sqlite3.db
11
+ postgresql:
12
+ adapter: postgresql
13
+ username: postgres
14
+ password: postgres
15
+ database: plugin_test
16
+ mysql:
17
+ adapter: mysql
18
+ host: localhost
19
+ username: root
20
+ password:
21
+ database: plugin_test
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ HasDefaultSpecApp::Application.initialize!
File without changes
@@ -0,0 +1,35 @@
1
+ HasDefaultSpecApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ # Tell Action Mailer not to deliver emails to the real world.
24
+ # The :test delivery method accumulates sent emails in the
25
+ # ActionMailer::Base.deliveries array.
26
+ config.action_mailer.delivery_method = :test
27
+
28
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
29
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
30
+ # like if you have constraints or database-specific column types
31
+ # config.active_record.schema_format = :sql
32
+
33
+ # Print deprecation notices to the stderr
34
+ config.active_support.deprecation = :stderr
35
+ end