rspeckled 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +2 -0
  3. data/LICENSE.txt +19 -0
  4. data/README.md +2 -0
  5. data/Rakefile +1 -0
  6. data/lib/rspeckled/helpers/factories.rb +3 -0
  7. data/lib/rspeckled/helpers/null_objects.rb +3 -0
  8. data/lib/rspeckled/helpers/session_helpers.rb +5 -0
  9. data/lib/rspeckled/helpers.rb +3 -0
  10. data/lib/rspeckled/mock_authentications/omniauth/ebay.rb +24 -0
  11. data/lib/rspeckled/mock_authentications/omniauth/facebook.rb +43 -0
  12. data/lib/rspeckled/mock_authentications/omniauth/twitter.rb +43 -0
  13. data/lib/rspeckled/mock_authentications/omniauth.rb +1 -0
  14. data/lib/rspeckled/plugins/authentication.rb +111 -0
  15. data/lib/rspeckled/plugins/bullet.rb +25 -0
  16. data/lib/rspeckled/plugins/carrier_wave.rb +34 -0
  17. data/lib/rspeckled/plugins/code_climate.rb +8 -0
  18. data/lib/rspeckled/plugins/database_cleaner.rb +49 -0
  19. data/lib/rspeckled/plugins/devise.rb +23 -0
  20. data/lib/rspeckled/plugins/elasticsearch.rb +32 -0
  21. data/lib/rspeckled/plugins/email.rb +27 -0
  22. data/lib/rspeckled/plugins/factory_girl.rb +20 -0
  23. data/lib/rspeckled/plugins/fakeredis.rb +4 -0
  24. data/lib/rspeckled/plugins/features.rb +38 -0
  25. data/lib/rspeckled/plugins/mocks.rb +14 -0
  26. data/lib/rspeckled/plugins/omniauth.rb +45 -0
  27. data/lib/rspeckled/plugins/rails/engine.rb +10 -0
  28. data/lib/rspeckled/plugins/rails/strong_parameters.rb +13 -0
  29. data/lib/rspeckled/plugins/recaptcha.rb +12 -0
  30. data/lib/rspeckled/plugins/referehencible.rb +21 -0
  31. data/lib/rspeckled/plugins/shoulda.rb +40 -0
  32. data/lib/rspeckled/plugins/sidekiq.rb +29 -0
  33. data/lib/rspeckled/plugins/simple_cov.rb +13 -0
  34. data/lib/rspeckled/plugins/singleton.rb +23 -0
  35. data/lib/rspeckled/plugins/stripe.rb +33 -0
  36. data/lib/rspeckled/plugins/test_after_commit.rb +4 -0
  37. data/lib/rspeckled/plugins/timecop.rb +35 -0
  38. data/lib/rspeckled/plugins/vcr.rb +38 -0
  39. data/lib/rspeckled/plugins/webmock.rb +25 -0
  40. data/lib/rspeckled/plugins/wisper.rb +14 -0
  41. data/lib/rspeckled/plugins.rb +25 -0
  42. data/lib/rspeckled/spec_helpers/active_record_basic.rb +4 -0
  43. data/lib/rspeckled/spec_helpers/active_record_connection_setup.rb +25 -0
  44. data/lib/rspeckled/spec_helpers/rails_engine.rb +16 -0
  45. data/lib/rspeckled/support/expectations.rb +6 -0
  46. data/lib/rspeckled/support/failures.rb +5 -0
  47. data/lib/rspeckled/support/focused.rb +6 -0
  48. data/lib/rspeckled/support/formatters.rb +6 -0
  49. data/lib/rspeckled/support/garbage_collection.rb +59 -0
  50. data/lib/rspeckled/support/heroku.rb +1 -0
  51. data/lib/rspeckled/support/i18n.rb +5 -0
  52. data/lib/rspeckled/support/misc.rb +1 -0
  53. data/lib/rspeckled/support/mocks.rb +7 -0
  54. data/lib/rspeckled/support/output.rb +1 -0
  55. data/lib/rspeckled/support/pending.rb +3 -0
  56. data/lib/rspeckled/support/rails.rb +13 -0
  57. data/lib/rspeckled/support/random.rb +3 -0
  58. data/lib/rspeckled/support/selenium.rb +4 -0
  59. data/lib/rspeckled/support.rb +1 -0
  60. data/lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb +37 -0
  61. data/lib/rspeckled/version.rb +3 -0
  62. data/lib/rspeckled.rb +8 -0
  63. data.tar.gz.sig +4 -0
  64. metadata +169 -0
  65. metadata.gz.sig +0 -0
@@ -0,0 +1,21 @@
1
+ ##############################################################################
2
+ # Referehencible Plugin
3
+ ##############################################################################
4
+
5
+ begin
6
+ require 'referehencible'
7
+
8
+ RSpec.configure do |config|
9
+ config.before(:each, :mock_refs => lambda { |v| !!v }) do |example|
10
+ reference = if example.metadata[:mock_refs].is_a? TrueClass
11
+ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
12
+ else
13
+ example.metadata[:mock_refs]
14
+ end
15
+
16
+ allow(Referehencible).to receive(:reference_number).
17
+ and_return(reference)
18
+ end
19
+ end
20
+ rescue LoadError
21
+ end
@@ -0,0 +1,40 @@
1
+ ##############################################################################
2
+ # Shoulda Plugin
3
+ ##############################################################################
4
+
5
+ begin
6
+ require 'shoulda-matchers'
7
+ rescue LoadError
8
+ end
9
+
10
+ if defined? Shoulda
11
+ Shoulda::Matchers.configure do |config|
12
+ config.integrate do |with|
13
+ with.test_framework :rspec
14
+ end
15
+ end
16
+
17
+ if defined? ActiveRecord
18
+ Shoulda::Matchers.configure do |config|
19
+ config.integrate do |with|
20
+ with.library :active_record
21
+ end
22
+ end
23
+ end
24
+
25
+ if defined? ActiveModel
26
+ Shoulda::Matchers.configure do |config|
27
+ config.integrate do |with|
28
+ with.library :active_model
29
+ end
30
+ end
31
+ end
32
+
33
+ if defined? ActionController
34
+ Shoulda::Matchers.configure do |config|
35
+ config.integrate do |with|
36
+ with.library :action_controller
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'sidekiq/testing'
3
+
4
+ RSpec.configure do |config|
5
+ config.before(:each) do |example|
6
+ # Clears out the jobs for tests using the fake testing
7
+ Sidekiq::Worker.clear_all
8
+
9
+ if example.metadata[:queue] == :stub
10
+ Sidekiq::Testing.fake!
11
+ elsif example.metadata[:queue] == :immediately_execute
12
+ Sidekiq::Testing.inline!
13
+ @redis_connection = Redis.new
14
+
15
+ allow(Sidekiq::RedisConnection).to receive(:build_client).
16
+ and_return(@redis_connection)
17
+ elsif example.metadata[:type] == :feature
18
+ Sidekiq::Testing.inline!
19
+ @redis_connection = Redis.new
20
+
21
+ allow(Sidekiq::RedisConnection).to receive(:build_client).
22
+ and_return(@redis_connection)
23
+ else
24
+ Sidekiq::Testing.fake!
25
+ end
26
+ end
27
+ end
28
+ rescue LoadError
29
+ end
@@ -0,0 +1,13 @@
1
+ begin
2
+ unless RUBY_VERSION.start_with?('1.8')
3
+ require 'simplecov'
4
+
5
+ SimpleCov.start do
6
+ add_filter '/config/'
7
+ add_filter '/spec/'
8
+ add_filter '/test/'
9
+ add_filter '/features/'
10
+ end
11
+ end
12
+ rescue LoadError
13
+ end
@@ -0,0 +1,23 @@
1
+ ##############################################################################
2
+ # Singleton Plugin
3
+ ##############################################################################
4
+
5
+ RSpec.configure do |config|
6
+ config.around(:each, :singletons => lambda { |v| !!v }) do |example|
7
+ require 'singleton'
8
+
9
+ options = example.metadata[:singletons]
10
+ options = options.is_a?(TrueClass) ? described_class : options
11
+ singletons_to_reset = Array(options)
12
+
13
+ singletons_to_reset.each do |singleton|
14
+ Singleton.__init__(singleton)
15
+ end
16
+
17
+ example.run
18
+
19
+ singletons_to_reset.each do |singleton|
20
+ Singleton.__init__(singleton)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ ##############################################################################
2
+ # Stripe Plugin
3
+ ##############################################################################
4
+
5
+ begin
6
+ require 'stripe'
7
+
8
+ RSpec.configure do |config|
9
+ config.after(:each, :stripe => true) do
10
+ if defined?(VCR)
11
+ vcr_turned_on = VCR.turned_on?
12
+ VCR.turn_off!
13
+ end
14
+
15
+ if defined?(WebMock)
16
+ webmock_net_connect = WebMock.net_connect_allowed?
17
+ WebMock.allow_net_connect!
18
+ end
19
+
20
+ begin
21
+ Stripe::Plan.all(:count => 100).each do |plan|
22
+ plan.delete if plan.id.match(/test/i) || plan.name.match(/test/i)
23
+ end
24
+
25
+ Stripe::Customer.all(:count => 100).each(&:delete)
26
+ ensure
27
+ VCR.turn_on! if defined?(VCR) && vcr_turned_on
28
+ WebMock.allow_net_connect! if defined?(WebMock) && webmock_net_connect
29
+ end
30
+ end
31
+ end
32
+ rescue LoadError
33
+ end
@@ -0,0 +1,4 @@
1
+ begin
2
+ require 'test_after_commit'
3
+ rescue LoadError
4
+ end
@@ -0,0 +1,35 @@
1
+ ##############################################################################
2
+ # Timecop Plugin
3
+ ##############################################################################
4
+
5
+ begin
6
+ require 'timecop'
7
+
8
+ RSpec.configure do |config|
9
+ config.around(:each, :time_mock => lambda { |v| !!v }) do |example|
10
+ options = example.metadata[:time_mock]
11
+ options = case options
12
+ when Time
13
+ { :time => options }
14
+ when FalseClass
15
+ false
16
+ when TrueClass
17
+ {}
18
+ end
19
+
20
+ if options
21
+ mock_type = options.fetch(:type, :freeze)
22
+ time = options.fetch(:time, Time.utc(2012, 7, 26, 18, 0, 0))
23
+
24
+ Timecop.public_send(mock_type, time)
25
+ else
26
+ Timecop.return
27
+ end
28
+
29
+ example.run
30
+
31
+ Timecop.return
32
+ end
33
+ end
34
+ rescue LoadError
35
+ end
@@ -0,0 +1,38 @@
1
+ ##############################################################################
2
+ # VCR Plugin
3
+ ##############################################################################
4
+
5
+ begin
6
+ require 'vcr'
7
+ Dir[File.expand_path('../../vcr_matchers/**/*.rb', __FILE__)].each { |f| require f }
8
+
9
+ begin
10
+ require 'webmock'
11
+
12
+ VCR.configure do |config|
13
+ config.hook_into :webmock
14
+ end
15
+ rescue LoadError
16
+ end
17
+
18
+ begin
19
+ require 'faraday'
20
+
21
+ VCR.configure do |config|
22
+ config.hook_into :faraday
23
+ end
24
+ rescue LoadError
25
+ end
26
+
27
+ VCR.configure do |config|
28
+ config.ignore_hosts 'lvh.me', 'localhost', '127.0.0.1', '0.0.0.0'
29
+ config.cassette_library_dir = File.expand_path('./tmp/vcr_cassettes')
30
+
31
+ # So that the Code Climate coverage reporter (if installed) can send reports
32
+ # even though VCR is enabled.
33
+ config.ignore_hosts 'codeclimate.com'
34
+
35
+ config.configure_rspec_metadata!
36
+ end
37
+ rescue LoadError
38
+ end
@@ -0,0 +1,25 @@
1
+ ##############################################################################
2
+ # WebMock Plugin
3
+ ##############################################################################
4
+
5
+ begin
6
+ require 'webmock/rspec'
7
+
8
+ RSpec.configure do |config|
9
+ config.around(:each, :web_mock => lambda { |v| !!v }) do |example|
10
+ options = example.metadata[:web_mock]
11
+ options = case options
12
+ when TrueClass
13
+ { :allow_localhost => true }
14
+ end
15
+
16
+ WebMock.disable_net_connect!(options)
17
+
18
+ example.run
19
+
20
+ WebMock.allow_net_connect!
21
+ end
22
+ end
23
+
24
+ rescue LoadError
25
+ end
@@ -0,0 +1,14 @@
1
+ ##############################################################################
2
+ # Wisper
3
+ ##############################################################################
4
+
5
+ begin
6
+ require 'wisper'
7
+ require 'wisper/rspec/matchers'
8
+ require 'wisper/rspec/stub_wisper_publisher'
9
+
10
+ RSpec.configure do |config|
11
+ config.include(Wisper::RSpec::BroadcastMatcher)
12
+ end
13
+ rescue LoadError
14
+ end
@@ -0,0 +1,25 @@
1
+ require 'rspeckled/plugins/timecop'
2
+ require 'rspeckled/plugins/authentication'
3
+ require 'rspeckled/plugins/bullet'
4
+ require 'rspeckled/plugins/carrier_wave'
5
+ require 'rspeckled/plugins/database_cleaner'
6
+ require 'rspeckled/plugins/devise'
7
+ require 'rspeckled/plugins/elasticsearch'
8
+ require 'rspeckled/plugins/email'
9
+ require 'rspeckled/plugins/factory_girl'
10
+ require 'rspeckled/plugins/fakeredis'
11
+ require 'rspeckled/plugins/features'
12
+ require 'rspeckled/plugins/omniauth'
13
+ require 'rspeckled/plugins/mocks'
14
+ require 'rspeckled/plugins/rails/engine'
15
+ require 'rspeckled/plugins/rails/strong_parameters'
16
+ require 'rspeckled/plugins/recaptcha'
17
+ require 'rspeckled/plugins/referehencible'
18
+ require 'rspeckled/plugins/shoulda'
19
+ require 'rspeckled/plugins/sidekiq'
20
+ require 'rspeckled/plugins/singleton'
21
+ require 'rspeckled/plugins/stripe'
22
+ require 'rspeckled/plugins/test_after_commit'
23
+ require 'rspeckled/plugins/vcr'
24
+ require 'rspeckled/plugins/webmock'
25
+ require 'rspeckled/plugins/wisper'
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.join('..', 'active_record_connection_setup'), __FILE__)
2
+ require 'rspeckled'
3
+
4
+ Dir[File.join(Dir.pwd, 'spec', 'support', '**', '*.rb')].sort.each { |f| require f }
@@ -0,0 +1,25 @@
1
+ require 'active_record'
2
+ require 'fileutils'
3
+ require 'logger'
4
+ require 'yaml'
5
+
6
+ begin
7
+ FileUtils.mkdir 'log'
8
+ rescue Errno::EEXIST
9
+ end
10
+
11
+ log_file = File.join(Dir.pwd, 'log', 'activerecord.log')
12
+
13
+ rails_database_yaml_file_path = File.join(Dir.pwd, 'config', 'database.yml')
14
+ rails_engine_database_yaml_file_path = File.join(Dir.pwd, 'spec', 'dummy', 'config', 'database.yml')
15
+
16
+ database_yaml_file_path = if File.exist? rails_engine_database_yaml_file_path
17
+ rails_engine_database_yaml_file_path
18
+ else
19
+ rails_database_yaml_file_path
20
+ end
21
+
22
+ connection_info = YAML.load_file(database_yaml_file_path)['test']
23
+
24
+ ActiveRecord::Base.logger = Logger.new(log_file)
25
+ ActiveRecord::Base.establish_connection(connection_info)
@@ -0,0 +1,16 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require File.expand_path(File.join('..', 'active_record_connection_setup'), __FILE__)
4
+ require File.join(Dir.pwd, 'spec', 'dummy', 'config', 'environment')
5
+
6
+ require 'rspec/rails'
7
+
8
+ Pathname.glob("#{Dir.pwd}/app/*").each do |directory|
9
+ if directory.directory?
10
+ $LOAD_PATH.unshift(directory) unless $LOAD_PATH.include?(directory)
11
+ end
12
+ end
13
+
14
+ require 'rspeckled'
15
+
16
+ Dir[File.join(Dir.pwd, 'spec', 'support', '**', '*.rb')].sort.each { |f| require f }
@@ -0,0 +1,6 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |c|
3
+ c.syntax = :expect
4
+ c.include_chain_clauses_in_custom_matcher_descriptions = true
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |config|
2
+ if config.respond_to?(:example_status_persistence_file_path=)
3
+ config.example_status_persistence_file_path = 'tmp/rspec_examples.txt'
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.configure do |config|
2
+ config.filter_run :focused => true
3
+ config.alias_example_to :fit, :focused => true
4
+
5
+ config.run_all_when_everything_filtered = true
6
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.configure do |config|
2
+ config.color = true
3
+
4
+ config.add_formatter 'Fuubar'
5
+ config.add_formatter 'documentation', 'tmp/rspec.txt'
6
+ end
@@ -0,0 +1,59 @@
1
+ ###
2
+ #
3
+ # Shamelessly stolen from http://ariejan.net/2011/09/24/rspec-speed-up-by-tweaking-ruby-garbage-collection/
4
+ #
5
+ module Rspeckled
6
+ class DeferredGarbageCollection
7
+ THRESHOLD = (ENV['DEFER_GC'] || 20.0).to_f
8
+
9
+ @garbage_last_collected_at = nil
10
+
11
+ def self.start
12
+ cycle_garbage_collector if enabled?
13
+ end
14
+
15
+ def self.reconsider
16
+ if enabled? && over_deferrment_threshold?
17
+ cycle_garbage_collector
18
+
19
+ self.garbage_last_collected_at = Time.now
20
+ end
21
+ end
22
+
23
+ def self.cycle_garbage_collector
24
+ GC.enable
25
+ GC.start
26
+ GC.disable
27
+ end
28
+
29
+ def self.over_deferrment_threshold?
30
+ time_since_garbage_last_collected >= THRESHOLD
31
+ end
32
+
33
+ def self.enabled?
34
+ THRESHOLD > 0
35
+ end
36
+
37
+ def self.time_since_garbage_last_collected
38
+ Time.now - garbage_last_collected_at
39
+ end
40
+
41
+ def self.garbage_last_collected_at
42
+ @garbage_last_collected_at || Time.now
43
+ end
44
+
45
+ class << self
46
+ attr_writer :garbage_last_collected_at
47
+ end
48
+ end
49
+ end
50
+
51
+ RSpec.configure do |config|
52
+ config.before(:all) do
53
+ Rspeckled::DeferredGarbageCollection.start
54
+ end
55
+
56
+ config.after(:all) do
57
+ Rspeckled::DeferredGarbageCollection.reconsider
58
+ end
59
+ end
@@ -0,0 +1 @@
1
+ abort('DATABASE_URL environment variable is set') if ENV['DATABASE_URL']
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |config|
2
+ if defined? AbstractController::Translation
3
+ config.include AbstractController::Translation
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ RSpec.configure(&:disable_monkey_patching!)
@@ -0,0 +1,7 @@
1
+ RSpec.configure do |config|
2
+ config.mock_with :rspec do |mocks|
3
+ mocks.verify_partial_doubles = true
4
+ mocks.verify_doubled_constant_names = true
5
+ mocks.syntax = :expect
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require 'pp'
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.alias_example_to :pit, :pending => true
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'rspeckled/plugins/rails/engine'
2
+
3
+ if defined? RSpec::Rails
4
+ RSpec.configure do |config|
5
+ config.infer_base_class_for_anonymous_controllers = true
6
+
7
+ config.infer_spec_type_from_file_location! if config.respond_to?(:infer_spec_type_from_file_location!)
8
+
9
+ if Pathname.pwd.join('spec', 'dummy', 'config', 'environment.rb').exist?
10
+ config.include Rspeckled::NamespacedEngineControllerRouteFix, :type => :controller
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.order = 'random'
3
+ end
@@ -0,0 +1,4 @@
1
+ # For when you just have to know what the hell the browser is doing
2
+ RSpec.configure do |config|
3
+ config.alias_example_to :sit, :focused => true, :js => true, :driver => :selenium
4
+ end
@@ -0,0 +1 @@
1
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
@@ -0,0 +1,37 @@
1
+ module Rspeckled
2
+ module VcrMatchers
3
+ class UriWithoutTrailingId
4
+ attr_accessor :trailing_id_matcher
5
+
6
+ def initialize(trailing_id_matcher)
7
+ self.trailing_id_matcher = trailing_id_matcher
8
+ end
9
+
10
+ def call(request, vcr_cassette_request)
11
+ request_uri = request.uri
12
+ vcr_cassette_request_uri = vcr_cassette_request.uri
13
+
14
+ if request_uri.match(trailing_id_matcher)
15
+ request_uri_without_id = request_uri.sub trailing_id_matcher, ''
16
+ vcr_cassette_request_uri_without_id = vcr_cassette_request_uri.sub trailing_id_matcher, ''
17
+
18
+ request_uri.match(trailing_id_matcher) &&
19
+ vcr_cassette_request_uri.match(trailing_id_matcher) &&
20
+ request_uri_without_id == vcr_cassette_request_uri_without_id
21
+ else
22
+ request_uri == vcr_cassette_request_uri
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ VCR.configure do |config|
30
+ config.register_request_matcher :uri_without_trailing_guid do |request, vcr_cassette_request|
31
+ Rspeckled::VcrMatchers::UriWithoutTrailingId.new(%r(/[a-f0-9\-]{32,36}/?\z)).call(request, vcr_cassette_request)
32
+ end
33
+
34
+ config.register_request_matcher :uri_without_trailing_id do |request, vcr_cassette_request|
35
+ Rspeckled::VcrMatchers::UriWithoutTrailingId.new(%r{/\d+/?\z}).call(request, vcr_cassette_request)
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Rspeckled
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/rspeckled.rb ADDED
@@ -0,0 +1,8 @@
1
+ # These Plugins Must Be Loaded Before Anything Else
2
+ require 'rspeckled/plugins/code_climate'
3
+ require 'rspeckled/plugins/simple_cov'
4
+
5
+ require 'rspeckled/support'
6
+ require 'rspeckled/helpers'
7
+ require 'rspeckled/plugins'
8
+ # require 'rspeckled/matchers'
data.tar.gz.sig ADDED
@@ -0,0 +1,4 @@
1
+ w�4�9�Bn)��\*J[�FD�)j\�����N��������4�v��k:��[�"���6��<���M�q�u�Ԓ���I@�9ܻ�d��+�ڧ�*)�0
2
+ ���J^3W���(s�
3
+ ���H(��Ⱦ�2�\�ʫO'���p�
4
+ �"!���Ôm� fT/)S�����p�H�� ���@�9$��7q-���1W+��w*�g��.,�N#W��`