rspec_candy 0.3.1 → 0.4.0

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.
Files changed (83) hide show
  1. data/.gitignore +1 -0
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +5 -4
  4. data/README.md +5 -13
  5. data/Rakefile +18 -25
  6. data/gemfiles/Gemfile.rspec1-rails2 +17 -0
  7. data/gemfiles/Gemfile.rspec1-rails2.lock +31 -0
  8. data/gemfiles/Gemfile.rspec2-rails3 +9 -0
  9. data/gemfiles/Gemfile.rspec2-rails3.lock +51 -0
  10. data/gemfiles/Gemfile.rspec3-rails4 +9 -0
  11. data/gemfiles/Gemfile.rspec3-rails4.lock +61 -0
  12. data/lib/rspec_candy/base.rb +1 -0
  13. data/lib/rspec_candy/helpers.rb +1 -1
  14. data/lib/rspec_candy/helpers/it_should_act_like.rb +2 -2
  15. data/lib/rspec_candy/helpers/rails/it_should_run_callbacks.rb +6 -26
  16. data/lib/rspec_candy/helpers/rails/store_with_values.rb +7 -2
  17. data/lib/rspec_candy/helpers/stub_any_instance.rb +2 -2
  18. data/lib/rspec_candy/switcher.rb +27 -15
  19. data/lib/rspec_candy/version.rb +1 -1
  20. data/spec/{shared/rspec_candy → rspec_candy}/helpers/disposable_copy_spec.rb +1 -1
  21. data/spec/{shared/rspec_candy → rspec_candy}/helpers/it_should_act_like_spec.rb +0 -0
  22. data/spec/{shared/rspec_candy → rspec_candy}/helpers/new_with_stubs_spec.rb +0 -0
  23. data/spec/rspec_candy/helpers/rails/it_should_run_callbacks_spec.rb +84 -0
  24. data/spec/{shared/rspec_candy → rspec_candy}/helpers/rails/prevent_storage_spec.rb +1 -1
  25. data/spec/{shared/rspec_candy → rspec_candy}/helpers/rails/store_with_values_spec.rb +6 -2
  26. data/spec/{shared/rspec_candy → rspec_candy}/helpers/should_receive_and_execute_spec.rb +0 -0
  27. data/spec/{shared/rspec_candy → rspec_candy}/helpers/should_receive_and_return_spec.rb +0 -0
  28. data/spec/{shared/rspec_candy → rspec_candy}/helpers/should_receive_chain_spec.rb +0 -0
  29. data/spec/{shared/rspec_candy → rspec_candy}/helpers/stub_any_instance_spec.rb +0 -0
  30. data/spec/{shared/rspec_candy → rspec_candy}/helpers/stub_existing_spec.rb +0 -0
  31. data/spec/{shared/rspec_candy → rspec_candy}/matchers/be_same_number_as_spec.rb +0 -0
  32. data/spec/{shared/rspec_candy → rspec_candy}/matchers/be_same_second_as_spec.rb +0 -0
  33. data/spec/{shared/rspec_candy → rspec_candy}/matchers/include_hash_spec.rb +0 -0
  34. data/spec/{rspec1/app_root/config/environments/test.rb → shared_examples/.keep} +0 -0
  35. data/spec/spec_helper.rb +9 -0
  36. data/spec/support/database.rb +15 -0
  37. data/spec/support/database_cleaner.rb +20 -0
  38. data/spec/{shared/support → support}/matchers/pass_as_describe_block.rb +14 -3
  39. data/spec/{shared/support → support}/matchers/pass_as_example.rb +2 -0
  40. data/spec/{shared/app_root/app/models/model.rb → support/models.rb} +19 -0
  41. metadata +74 -123
  42. data/spec/rspec1/Gemfile +0 -16
  43. data/spec/rspec1/Gemfile.lock +0 -74
  44. data/spec/rspec1/Rakefile +0 -11
  45. data/spec/rspec1/app_root/config/boot.rb +0 -114
  46. data/spec/rspec1/app_root/config/database.yml +0 -4
  47. data/spec/rspec1/app_root/config/environment.rb +0 -14
  48. data/spec/rspec1/app_root/config/initializers/state_machine.rb +0 -1
  49. data/spec/rspec1/app_root/config/routes.rb +0 -4
  50. data/spec/rspec1/rcov.opts +0 -2
  51. data/spec/rspec1/spec.opts +0 -4
  52. data/spec/rspec1/spec/spec_helper.rb +0 -25
  53. data/spec/rspec1/spec/switcher_spec.rb +0 -26
  54. data/spec/rspec2/.rspec +0 -2
  55. data/spec/rspec2/Gemfile +0 -14
  56. data/spec/rspec2/Gemfile.lock +0 -137
  57. data/spec/rspec2/Rakefile +0 -11
  58. data/spec/rspec2/app_root/.gitignore +0 -4
  59. data/spec/rspec2/app_root/config/application.rb +0 -32
  60. data/spec/rspec2/app_root/config/boot.rb +0 -13
  61. data/spec/rspec2/app_root/config/database.yml +0 -4
  62. data/spec/rspec2/app_root/config/environment.rb +0 -5
  63. data/spec/rspec2/app_root/config/environments/test.rb +0 -0
  64. data/spec/rspec2/app_root/config/initializers/backtrace_silencers.rb +0 -7
  65. data/spec/rspec2/app_root/config/initializers/inflections.rb +0 -10
  66. data/spec/rspec2/app_root/config/initializers/mime_types.rb +0 -5
  67. data/spec/rspec2/app_root/config/initializers/secret_token.rb +0 -7
  68. data/spec/rspec2/app_root/config/initializers/session_store.rb +0 -8
  69. data/spec/rspec2/app_root/config/initializers/state_machine.rb +0 -1
  70. data/spec/rspec2/app_root/config/locales/en.yml +0 -5
  71. data/spec/rspec2/app_root/config/routes.rb +0 -58
  72. data/spec/rspec2/rcov.opts +0 -2
  73. data/spec/rspec2/spec/spec_helper.rb +0 -24
  74. data/spec/rspec2/spec/switcher_spec.rb +0 -21
  75. data/spec/shared/app_root/app/controllers/application_controller.rb +0 -2
  76. data/spec/shared/app_root/app/models/state_machine_model.rb +0 -53
  77. data/spec/shared/app_root/app/models/sti_child.rb +0 -3
  78. data/spec/shared/app_root/app/models/sti_parent.rb +0 -12
  79. data/spec/shared/app_root/config/initializers/state_machine.rb +0 -1
  80. data/spec/shared/app_root/db/migrate/001_create_model.rb +0 -14
  81. data/spec/shared/app_root/db/migrate/002_create_state_machine_model.rb +0 -13
  82. data/spec/shared/app_root/db/migrate/003_create_sti_model.rb +0 -14
  83. data/spec/shared/rspec_candy/helpers/rails/it_should_run_callbacks_spec.rb +0 -158
data/spec/rspec2/Rakefile DELETED
@@ -1,11 +0,0 @@
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
@@ -1,4 +0,0 @@
1
- .bundle
2
- db/*.sqlite3
3
- log/*.log
4
- tmp/**/*
@@ -1,32 +0,0 @@
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
@@ -1,13 +0,0 @@
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)
@@ -1,4 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- database: ":memory:"
4
- verbosity: quiet
@@ -1,5 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
- # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
-
6
- # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
- # Rails.backtrace_cleaner.remove_silencers!
@@ -1,10 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new inflection rules using the following format
4
- # (all these examples are active by default):
5
- # ActiveSupport::Inflector.inflections do |inflect|
6
- # inflect.plural /^(ox)$/i, '\1en'
7
- # inflect.singular /^(ox)en/i, '\1'
8
- # inflect.irregular 'person', 'people'
9
- # inflect.uncountable %w( fish sheep )
10
- # end
@@ -1,5 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf
5
- # Mime::Type.register_alias "text/html", :iphone
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
- # Make sure the secret is at least 30 characters and all random,
6
- # no regular words or you'll be exposed to dictionary attacks.
7
- HasDefaultSpecApp::Application.config.secret_token = 'cb014a08a45243e7143f31e04774c342c1fba329fd594ae1a480d8283b1a851f425dc08044311fb4be6d000b6e6681de7c76d19148419a5ffa0a9f84556d3b33'
@@ -1,8 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- HasDefaultSpecApp::Application.config.session_store :cookie_store, :key => '_app_root_session'
4
-
5
- # Use the database for sessions instead of the cookie-based default,
6
- # which shouldn't be used to store highly confidential information
7
- # (create the session table with "rails generate session_migration")
8
- # HasDefaultSpecApp::Application.config.session_store :active_record_store
@@ -1 +0,0 @@
1
- Bundler.require(:state_machine) if ENV['REQUIRE_STATE_MACHINE'] == 'true'
@@ -1,5 +0,0 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
-
4
- en:
5
- hello: "Hello world"
@@ -1,58 +0,0 @@
1
- HasDefaultSpecApp::Application.routes.draw do
2
- # The priority is based upon order of creation:
3
- # first created -> highest priority.
4
-
5
- # Sample of regular route:
6
- # match 'products/:id' => 'catalog#view'
7
- # Keep in mind you can assign values other than :controller and :action
8
-
9
- # Sample of named route:
10
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
- # This route can be invoked with purchase_url(:id => product.id)
12
-
13
- # Sample resource route (maps HTTP verbs to controller actions automatically):
14
- # resources :products
15
-
16
- # Sample resource route with options:
17
- # resources :products do
18
- # member do
19
- # get 'short'
20
- # post 'toggle'
21
- # end
22
- #
23
- # collection do
24
- # get 'sold'
25
- # end
26
- # end
27
-
28
- # Sample resource route with sub-resources:
29
- # resources :products do
30
- # resources :comments, :sales
31
- # resource :seller
32
- # end
33
-
34
- # Sample resource route with more complex sub-resources
35
- # resources :products do
36
- # resources :comments
37
- # resources :sales do
38
- # get 'recent', :on => :collection
39
- # end
40
- # end
41
-
42
- # Sample resource route within a namespace:
43
- # namespace :admin do
44
- # # Directs /admin/products/* to Admin::ProductsController
45
- # # (app/controllers/admin/products_controller.rb)
46
- # resources :products
47
- # end
48
-
49
- # You can have the root of your site routed with "root"
50
- # just remember to delete public/index.html.
51
- # root :to => "welcome#index"
52
-
53
- # See how all your routes lay out with "rake routes"
54
-
55
- # This is a legacy wild controller route that's not recommended for RESTful applications.
56
- # Note: This route will make all actions in every controller accessible via GET requests.
57
- match ':controller(/:action(/:id(.:format)))'
58
- end
@@ -1,2 +0,0 @@
1
- --exclude "spec/*,gems/*"
2
- --rails
@@ -1,24 +0,0 @@
1
- $: << File.join(File.dirname(__FILE__), "/../lib" )
2
-
3
- ENV['RAILS_ENV'] = 'test'
4
- ENV['RAILS_ROOT'] = 'app_root'
5
-
6
- # Load the Rails environment and testing framework
7
- require "#{File.dirname(__FILE__)}/../app_root/config/environment"
8
- require 'rspec/rails'
9
-
10
- # Load dependencies
11
- require 'rspec_candy/all'
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
- RSpec.configure do |config|
22
- config.use_transactional_fixtures = true
23
- config.use_instantiated_fixtures = false
24
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RSpecCandy::Switcher do
4
-
5
- describe "#rspec_version" do
6
-
7
- it "should detect rspec2" do
8
- RSpecCandy::Switcher.rspec_version.should == :rspec2
9
- end
10
-
11
- end
12
-
13
- describe '#rspec_root' do
14
-
15
- it 'should return the RSpec module' do
16
- RSpecCandy::Switcher.rspec_root.should == RSpec
17
- end
18
-
19
- end
20
-
21
- end
@@ -1,2 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- end
@@ -1,53 +0,0 @@
1
- class StateMachineModel < ActiveRecord::Base
2
-
3
- if respond_to?(:state_machine)
4
-
5
- state_machine :initial => :state1 do
6
-
7
- state :state1
8
-
9
- state :state2
10
-
11
- state :state3
12
-
13
- event :event do
14
- transition :state1 => :state2
15
- end
16
-
17
- event :another_event do
18
- transition :state1 => :state3
19
- end
20
-
21
- after_transition :state1 => :state2, :do => :event_callback
22
-
23
- end
24
-
25
- state_machine :custom_state, :initial => :state1 do
26
-
27
- state :state1
28
-
29
- state :state2
30
-
31
- state :state3
32
-
33
- event :event do
34
- transition :state1 => :state2
35
- end
36
-
37
- event :another_event do
38
- transition :state1 => :state3
39
- end
40
-
41
- after_transition :state1 => :state2, :do => :custom_state_event_callback
42
-
43
- end
44
-
45
- def event_callback
46
- end
47
-
48
- def custom_state_event_callback
49
- end
50
-
51
- end
52
-
53
- end
@@ -1,3 +0,0 @@
1
- class StiChild < StiParent
2
-
3
- end
@@ -1,12 +0,0 @@
1
- class StiParent < ActiveRecord::Base
2
-
3
- self.table_name = 'sti_models'
4
-
5
- before_save :crash
6
- validate :crash
7
-
8
- def crash
9
- raise 'callback was run'
10
- end
11
-
12
- end
@@ -1 +0,0 @@
1
- Bundler.require(:state_machine) if ENV['REQUIRE_STATE_MACHINE'] == 'true'
@@ -1,14 +0,0 @@
1
- class CreateModel < ActiveRecord::Migration
2
-
3
- def self.up
4
- create_table :models do |t|
5
- t.string :string_field
6
- t.references :associated_model
7
- end
8
- end
9
-
10
- def self.down
11
- drop_table :models
12
- end
13
-
14
- end
@@ -1,13 +0,0 @@
1
- class CreateStateMachineModel < ActiveRecord::Migration
2
-
3
- def self.up
4
- create_table :state_machine_models do |t|
5
- t.string :state
6
- end
7
- end
8
-
9
- def self.down
10
- drop_table :state_machine_models
11
- end
12
-
13
- end
@@ -1,14 +0,0 @@
1
- class CreateStiModel < ActiveRecord::Migration
2
-
3
- def self.up
4
- create_table :sti_models do |t|
5
- t.string :type
6
- t.string :string_field
7
- end
8
- end
9
-
10
- def self.down
11
- drop_table :sti_models
12
- end
13
-
14
- end
@@ -1,158 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RSpecCandy::Helpers::Rails::ItShouldRunCallbacks do
4
-
5
- describe '#it_should_run_callbacks' do
6
-
7
- context 'for an app without state_machine' do
8
-
9
- it 'should pass if all callbacks have been run' do
10
- <<-describe_block.should pass_as_describe_block
11
- describe Model, '#after_save' do
12
- it_should_run_callbacks :after_save_callback2, :after_save_callback1
13
- end
14
- describe_block
15
- end
16
-
17
- it 'should only attempt to run the proper callbacks have been run' do
18
- <<-describe_block.should fail_as_describe_block
19
- describe Model, '#before_save' do
20
- it_should_run_callbacks :after_save_callback2, :after_save_callback1
21
- end
22
- describe_block
23
- end
24
-
25
- it 'should not pass if a callback has not been run' do
26
- <<-describe_block.should fail_as_describe_block
27
- describe Model, '#after_create' do
28
- it_should_run_callbacks :after_create_callback, :unknown_callback
29
- end
30
- describe_block
31
- end
32
-
33
- it 'should not actually execute the callbacks' do
34
- <<-describe_block.should pass_as_describe_block
35
- def Model.after_save_callback2
36
- raise "called!"
37
- end
38
-
39
- describe Model, '#after_save' do
40
- it_should_run_callbacks :after_save_callback1
41
- end
42
- describe_block
43
- end
44
-
45
- it 'should not parse state_machine callbacks being present' do
46
- <<-describe_block.should fail_as_describe_block
47
- describe StateMachineModel, '#event from :state1 to :state2' do
48
- it_should_run_callbacks :event_callback
49
- end
50
- describe_block
51
- end
52
-
53
- end
54
-
55
- context 'for an app with state_machine' do
56
-
57
- before do
58
- ENV['REQUIRE_STATE_MACHINE'] = 'true'
59
- end
60
-
61
- after do
62
- ENV['REQUIRE_STATE_MACHINE'] = 'false'
63
- end
64
-
65
- it 'should pass if all callbacks have been run' do
66
- <<-describe_block.should pass_as_describe_block
67
- describe Model, '#after_save' do
68
- it_should_run_callbacks :after_save_callback2, :after_save_callback1
69
- end
70
- describe_block
71
- end
72
-
73
- it 'should not pass if a callback has not been run' do
74
- <<-describe_block.should fail_as_describe_block
75
- describe Model, '#after_create' do
76
- it_should_run_callbacks :after_create_callback, :unknown_callback
77
- end
78
- describe_block
79
- end
80
-
81
-
82
- it 'should also run state machine callbacks and pass if they are called if StateMachine is present' do
83
- <<-describe_block.should pass_as_describe_block
84
- describe StateMachineModel, '#event from :state1 to :state2' do
85
- it_should_run_callbacks :event_callback
86
- end
87
- describe_block
88
- end
89
-
90
- it 'should also run state machine callbacks and fail if they are not called if StateMachine is present' do
91
- <<-describe_block.should fail_as_describe_block
92
- describe StateMachineModel, '#event from :state1 to :state3' do
93
- it_should_run_callbacks :event_callback
94
- end
95
- describe_block
96
- end
97
-
98
- it 'should also run state machine callbacks for a state machine with a custom name and pass if they are called if StateMachine is present' do
99
- <<-describe_block.should pass_as_describe_block
100
- describe StateMachineModel, '#event on :custom_state from :state1 to :state2' do
101
- it_should_run_callbacks :custom_state_event_callback
102
- end
103
- describe_block
104
- end
105
-
106
- it 'should also run state machine callbacks for a state machine with a custom name and fail if they are not called if StateMachine is present' do
107
- <<-describe_block.should fail_as_describe_block
108
- describe StateMachineModel, '#event on :custom_state from :state1 to :state3' do
109
- it_should_run_callbacks :custom_state_event_callback
110
- end
111
- describe_block
112
- end
113
-
114
- end
115
-
116
-
117
- end
118
-
119
- describe '#it_should_run_callbacks_in_order' do
120
-
121
- supported_callbacks = case RSpecCandy::Switcher.rspec_version
122
- when :rspec1
123
- %w[before after]
124
- when :rspec2
125
- %w[before after around]
126
- end
127
-
128
- supported_callbacks.each do |kind|
129
-
130
- it "should pass if all #{kind} callbacks are run in order" do
131
- <<-describe_block.should pass_as_describe_block
132
- describe Model, '##{kind}_save' do
133
- it_should_run_callbacks_in_order :#{kind}_save_callback1, :#{kind}_save_callback2
134
- end
135
- describe_block
136
- end
137
-
138
- it "should not pass if a #{kind} callback has not been run" do
139
- <<-describe_block.should fail_as_describe_block
140
- describe Model, '##{kind}_create' do
141
- it_should_run_callbacks_in_order :#{kind}_create_callback, :unknown_callback
142
- end
143
- describe_block
144
- end
145
-
146
- it "should not pass if #{kind} callbacks are run out of order" do
147
- <<-describe_block.should fail_as_describe_block
148
- describe Model, '##{kind}_save' do
149
- it_should_run_callbacks_in_order :#{kind}_save_callback2, :#{kind}_save_callback1
150
- end
151
- describe_block
152
- end
153
-
154
- end
155
-
156
- end
157
-
158
- end