rspec_candy 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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/.gitignore CHANGED
@@ -3,3 +3,4 @@ pkg
3
3
  *.gem
4
4
  .idea
5
5
  spec/**/app_root/log/*
6
+ Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/.travis.yml CHANGED
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.8.7"
4
3
  - "1.9.3"
5
- - ree
6
- before_script: rake travis_ci:prepare
7
- script: rake all:bundle all:spec
4
+ gemfile:
5
+ - gemfiles/Gemfile.rspec1-rails2
6
+ - gemfiles/Gemfile.rspec2-rails3
7
+ - gemfiles/Gemfile.rspec3-rails4
8
+ script: rake spec
8
9
  notifications:
9
10
  email:
10
11
  - fail@makandra.de
data/README.md CHANGED
@@ -3,7 +3,11 @@ rspec_candy [![Build Status](https://secure.travis-ci.org/makandra/rspec_candy.p
3
3
 
4
4
  A collection of nifty helpers and matchers for your RSpec suite.
5
5
 
6
- Will work for RSpec1 and Rails 2, or RSpec2 and Rails 3, or no Rails at all.
6
+ Tested on:
7
+
8
+ - RSpec 1 / Rails 2.3
9
+ - RSpec 2 / Rails 3.2
10
+ - RSpec 3 / Rails 4.2
7
11
 
8
12
 
9
13
  ##Installation
@@ -138,20 +142,8 @@ If you only care about the matchers or helpers you can also more specifically re
138
142
  it_should_run_callbacks :notify_this, :notify_that
139
143
  end
140
144
 
141
- If you use the state_machine gem, you can also spec callbacks for state_machine transitions:
142
-
143
-
144
- describe Model, '#my_event from :my_state1 to :my_state" do
145
- it_should_run_callbacks :notify_this, :notify_that
146
- end
147
145
 
148
146
 
149
- If you have used a custom state machine name, you can use specify it like this:
150
-
151
- describe Model, '#my_event on :my_machine from :my_state1 to :my_state" do
152
- it_should_run_callbacks :notify_this, :notify_that
153
- end
154
-
155
147
  **it_should_run_callbacks_in_order**
156
148
 
157
149
  Like `it_should_run_callbacks`, but also checks the correct order.
data/Rakefile CHANGED
@@ -1,48 +1,41 @@
1
1
  require 'rake'
2
-
3
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
4
3
 
5
4
  desc 'Default: Run all specs.'
6
5
  task :default => 'all:spec'
7
6
 
8
- namespace :travis_ci do
9
-
10
- desc 'Things to do before Travis CI begins'
11
- task :prepare => :slimgems
12
-
13
- desc 'Install slimgems'
14
- task :slimgems do
15
- system('gem install slimgems')
16
- end
17
-
7
+ task :spec do
8
+ rspec_binary = ENV['BUNDLE_GEMFILE'].include?('rspec1') ? 'spec' : 'rspec'
9
+ examples = ENV['SPEC'] || 'spec'
10
+ success &= system("bundle exec #{rspec_binary} #{examples}")
18
11
  end
19
12
 
20
13
  namespace :all do
21
14
 
22
- desc "Run specs on all spec apps"
15
+ desc "Run specs on all versions"
23
16
  task :spec do
24
17
  success = true
25
- for_each_directory_of('spec/**/Rakefile') do |directory|
26
- env = "SPEC=../../#{ENV['SPEC']} " if ENV['SPEC']
27
- success &= system("cd #{directory} && #{env} bundle exec rake spec")
18
+ for_each_gemfile do
19
+ Rake::Task['spec'].execute
28
20
  end
29
21
  fail "Tests failed" unless success
30
22
  end
31
23
 
32
- desc "Bundle all spec apps"
24
+ desc "Bundle all versions"
33
25
  task :bundle do
34
- for_each_directory_of('spec/**/Gemfile') do |directory|
35
- system("cd #{directory} && rm -f Gemfile.lock && bundle install")
26
+ for_each_gemfile do
27
+ system('bundle install')
36
28
  end
37
29
  end
38
30
 
39
31
  end
40
32
 
41
- def for_each_directory_of(path, &block)
42
- Dir[path].sort.each do |rakefile|
43
- directory = File.dirname(rakefile)
44
- puts '', "\033[44m#{directory}\033[0m", ''
45
- block.call(directory)
33
+ def for_each_gemfile
34
+ version = ENV['VERSION'] || '*'
35
+ Dir["gemfiles/Gemfile.#{version}"].sort.each do |gemfile|
36
+ next if gemfile =~ /.lock/
37
+ puts '', "\033[44m#{gemfile}\033[0m", ''
38
+ ENV['BUNDLE_GEMFILE'] = gemfile
39
+ yield
46
40
  end
47
41
  end
48
-
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ Deprecate.skip = true if defined?(Deprecate.skip)
4
+ Gem::Deprecate.skip = true if defined?(Gem::Deprecate.skip)
5
+
6
+ source 'https://rubygems.org'
7
+
8
+ gem 'activerecord', '~>2.3.18'
9
+ gem 'rspec', '~>1.3.2'
10
+ gem 'sqlite3'
11
+ gem 'database_cleaner'
12
+ gem 'rake'
13
+
14
+ gem 'rspec_candy', :path => '..'
15
+
16
+ # gem 'test-unit', '~>1.2', :platforms => :ruby_19
17
+ # gem 'hoe', '=2.8.0', :platforms => :ruby_19
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ rspec_candy (0.4.0)
5
+ rspec
6
+ sneaky-save
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activerecord (2.3.18)
13
+ activesupport (= 2.3.18)
14
+ activesupport (2.3.18)
15
+ database_cleaner (1.2.0)
16
+ rake (10.4.2)
17
+ rspec (1.3.2)
18
+ sneaky-save (0.0.2)
19
+ activerecord (>= 2.3.2)
20
+ sqlite3 (1.3.10)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ activerecord (~> 2.3.18)
27
+ database_cleaner
28
+ rake
29
+ rspec (~> 1.3.2)
30
+ rspec_candy!
31
+ sqlite3
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~>3.2.0'
4
+ gem 'rspec', '~>2.14.1'
5
+ gem 'sqlite3'
6
+ gem 'database_cleaner'
7
+ gem 'rake'
8
+
9
+ gem 'rspec_candy', :path => '..'
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ rspec_candy (0.4.0)
5
+ rspec
6
+ sneaky-save
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (3.2.21)
12
+ activesupport (= 3.2.21)
13
+ builder (~> 3.0.0)
14
+ activerecord (3.2.21)
15
+ activemodel (= 3.2.21)
16
+ activesupport (= 3.2.21)
17
+ arel (~> 3.0.2)
18
+ tzinfo (~> 0.3.29)
19
+ activesupport (3.2.21)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ multi_json (~> 1.0)
22
+ arel (3.0.3)
23
+ builder (3.0.4)
24
+ database_cleaner (1.2.0)
25
+ diff-lcs (1.2.5)
26
+ i18n (0.7.0)
27
+ multi_json (1.11.0)
28
+ rake (10.4.2)
29
+ rspec (2.14.1)
30
+ rspec-core (~> 2.14.0)
31
+ rspec-expectations (~> 2.14.0)
32
+ rspec-mocks (~> 2.14.0)
33
+ rspec-core (2.14.8)
34
+ rspec-expectations (2.14.5)
35
+ diff-lcs (>= 1.1.3, < 2.0)
36
+ rspec-mocks (2.14.6)
37
+ sneaky-save (0.1.0)
38
+ activerecord (>= 3.2.0)
39
+ sqlite3 (1.3.10)
40
+ tzinfo (0.3.43)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ activerecord (~> 3.2.0)
47
+ database_cleaner
48
+ rake
49
+ rspec (~> 2.14.1)
50
+ rspec_candy!
51
+ sqlite3
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~>4.2.0'
4
+ gem 'rspec', '~>3.2.0'
5
+ gem 'sqlite3'
6
+ gem 'database_cleaner'
7
+ gem 'rake'
8
+
9
+ gem 'rspec_candy', :path => '..'
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ rspec_candy (0.4.0)
5
+ rspec
6
+ sneaky-save
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (4.2.1)
12
+ activesupport (= 4.2.1)
13
+ builder (~> 3.1)
14
+ activerecord (4.2.1)
15
+ activemodel (= 4.2.1)
16
+ activesupport (= 4.2.1)
17
+ arel (~> 6.0)
18
+ activesupport (4.2.1)
19
+ i18n (~> 0.7)
20
+ json (~> 1.7, >= 1.7.7)
21
+ minitest (~> 5.1)
22
+ thread_safe (~> 0.3, >= 0.3.4)
23
+ tzinfo (~> 1.1)
24
+ arel (6.0.0)
25
+ builder (3.2.2)
26
+ database_cleaner (1.2.0)
27
+ diff-lcs (1.2.5)
28
+ i18n (0.7.0)
29
+ json (1.8.2)
30
+ minitest (5.5.1)
31
+ rake (10.4.2)
32
+ rspec (3.2.0)
33
+ rspec-core (~> 3.2.0)
34
+ rspec-expectations (~> 3.2.0)
35
+ rspec-mocks (~> 3.2.0)
36
+ rspec-core (3.2.3)
37
+ rspec-support (~> 3.2.0)
38
+ rspec-expectations (3.2.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.2.0)
41
+ rspec-mocks (3.2.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.2.0)
44
+ rspec-support (3.2.2)
45
+ sneaky-save (0.1.0)
46
+ activerecord (>= 3.2.0)
47
+ sqlite3 (1.3.10)
48
+ thread_safe (0.3.5)
49
+ tzinfo (1.2.2)
50
+ thread_safe (~> 0.1)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ activerecord (~> 4.2.0)
57
+ database_cleaner
58
+ rake
59
+ rspec (~> 3.2.0)
60
+ rspec_candy!
61
+ sqlite3
@@ -1,2 +1,3 @@
1
+ require 'active_record'
1
2
  require 'rspec_candy/version'
2
3
  require 'rspec_candy/switcher'
@@ -8,7 +8,7 @@ require 'rspec_candy/helpers/should_receive_chain'
8
8
  require 'rspec_candy/helpers/stub_any_instance'
9
9
  require 'rspec_candy/helpers/stub_existing'
10
10
 
11
- if RSpecCandy::Switcher.rails_loaded?
11
+ if RSpecCandy::Switcher.active_record_loaded?
12
12
  require 'rspec_candy/helpers/rails/store_with_values'
13
13
  require 'rspec_candy/helpers/rails/it_should_run_callbacks'
14
14
  require 'rspec_candy/helpers/rails/prevent_storage'
@@ -25,9 +25,9 @@ module RSpecCandy
25
25
  end
26
26
 
27
27
  case Switcher.rspec_version
28
- when :rspec1
28
+ when 1
29
29
  Spec::Example::ExampleGroupMethods.send(:include, self)
30
- when :rspec2
30
+ else
31
31
  RSpec::Core::ExampleGroup.singleton_class.send(:include, self)
32
32
  end
33
33
  end
@@ -18,17 +18,14 @@ module RSpecCandy
18
18
  should = ['should run callbacks', callbacks.inspect, ('in order' if options[:ordered]), reason].compact.join ' '
19
19
 
20
20
  prose = case Switcher.rspec_version
21
- when :rspec1
21
+ when 1
22
22
  description_parts.last
23
- when :rspec2
23
+ else
24
24
  description.split(/(?=#)/).last
25
25
  end
26
26
 
27
27
  send(:it, should) do
28
28
  extend ExampleMethods
29
- if subject.class.respond_to?(:state_machine) and defined?(StateMachine)
30
- extend StateMachineExampleMethods
31
- end
32
29
  callbacks.each do |callback|
33
30
  expectation = subject.should_receive(callback).once
34
31
  expectation.ordered if options[:ordered]
@@ -48,13 +45,13 @@ module RSpecCandy
48
45
  end
49
46
 
50
47
  case Switcher.rspec_version
51
- when :rspec1
48
+ when 1
52
49
 
53
50
  def run_active_record_callbacks_from_prose(prose)
54
51
  subject.run_callbacks(prose.sub(/^#/, ''))
55
52
  end
56
53
 
57
- when :rspec2
54
+ else
58
55
 
59
56
  def run_active_record_callbacks_from_prose(prose)
60
57
  hook = prose.split.last.sub(/^#/, '')
@@ -82,27 +79,10 @@ module RSpecCandy
82
79
  end
83
80
  end
84
81
 
85
- module StateMachineExampleMethods
86
- def run_all_callbacks(prose)
87
- run_state_machine_callbacks_from_prose(prose) or super
88
- end
89
-
90
- def run_state_machine_callbacks_from_prose(prose)
91
- if parts = prose.match(/^(#\w+) (?:on ([\:\w]+) )?from ([\:\w]+) to ([\:\w]+)$/)
92
- name = parts[1].sub(/^#/, '').to_sym
93
- machine_name = parts[2] ? parts[2].sub(/^:/, '').to_sym : :state
94
- from = parts[3].sub(/^:/, '').to_sym
95
- to = parts[4].sub(/^:/, '').to_sym
96
- transition = StateMachine::Transition.new(subject, subject.class.state_machine(machine_name), name, from, to)
97
- transition.run_callbacks
98
- end
99
- end
100
- end
101
-
102
82
  case Switcher.rspec_version
103
- when :rspec1
83
+ when 1
104
84
  Spec::Example::ExampleGroupMethods.send(:include, self::ExampleGroupMethods)
105
- when :rspec2
85
+ else
106
86
  RSpec::Core::ExampleGroup.singleton_class.send(:include, self::ExampleGroupMethods)
107
87
  end
108
88
 
@@ -5,13 +5,18 @@ module RSpecCandy
5
5
 
6
6
  def store_with_values(values = {})
7
7
  record = new
8
- if Switcher.rails_version == :rails2
8
+ case Switcher.active_record_version
9
+ when 2
9
10
  record.send(:attributes=, values, false)
10
11
  record.send(:create_without_callbacks)
11
- else
12
+ when 3
12
13
  require 'sneaky-save'
13
14
  record.assign_attributes(values, :without_protection => true)
14
15
  record.sneaky_save
16
+ else
17
+ require 'sneaky-save'
18
+ record.assign_attributes(values)
19
+ record.sneaky_save
15
20
  end
16
21
  record
17
22
  end
@@ -4,7 +4,7 @@ module RSpecCandy
4
4
 
5
5
  def stub_any_instance(stubs)
6
6
  case Switcher.rspec_version
7
- when :rspec1
7
+ when 1
8
8
  unstubbed_new = method(:new)
9
9
  stub(:new).and_return do |*args|
10
10
  unstubbed_new.call(*args).tap do |obj|
@@ -12,7 +12,7 @@ module RSpecCandy
12
12
  end
13
13
  end
14
14
  stubs
15
- when :rspec2
15
+ else
16
16
  any_instance.stub(stubs)
17
17
  end
18
18
  end