rspec-rails 3.0.0.beta2 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -1
  4. data/Capybara.md +1 -3
  5. data/Changelog.md +126 -58
  6. data/README.md +31 -4
  7. data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
  8. data/lib/generators/rspec/controller/templates/view_spec.rb +1 -1
  9. data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
  10. data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
  11. data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +21 -1
  12. data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
  13. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +1 -1
  14. data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
  15. data/lib/generators/rspec/observer/templates/observer_spec.rb +1 -1
  16. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +11 -3
  17. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +4 -3
  18. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  19. data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -4
  20. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +1 -1
  21. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  22. data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
  23. data/lib/rspec/rails.rb +1 -8
  24. data/lib/rspec/rails/configuration.rb +72 -0
  25. data/lib/rspec/rails/example.rb +0 -64
  26. data/lib/rspec/rails/example/controller_example_group.rb +16 -12
  27. data/lib/rspec/rails/example/feature_example_group.rb +0 -2
  28. data/lib/rspec/rails/example/helper_example_group.rb +0 -2
  29. data/lib/rspec/rails/example/mailer_example_group.rb +0 -1
  30. data/lib/rspec/rails/example/model_example_group.rb +0 -4
  31. data/lib/rspec/rails/example/request_example_group.rb +0 -2
  32. data/lib/rspec/rails/example/routing_example_group.rb +0 -2
  33. data/lib/rspec/rails/example/view_example_group.rb +1 -2
  34. data/lib/rspec/rails/extensions.rb +0 -1
  35. data/lib/rspec/rails/fixture_support.rb +0 -8
  36. data/lib/rspec/rails/matchers.rb +1 -0
  37. data/lib/rspec/rails/matchers/have_http_status.rb +355 -0
  38. data/lib/rspec/rails/matchers/routing_matchers.rb +1 -1
  39. data/lib/rspec/rails/tasks/rspec.rake +12 -5
  40. data/lib/rspec/rails/version.rb +1 -1
  41. data/lib/rspec/rails/view_rendering.rb +6 -34
  42. metadata +42 -316
  43. metadata.gz.sig +0 -0
  44. data/features/Generators.md +0 -25
  45. data/features/GettingStarted.md +0 -84
  46. data/features/README.md +0 -48
  47. data/features/RailsVersions.md +0 -4
  48. data/features/Transactions.md +0 -84
  49. data/features/Upgrade.md +0 -121
  50. data/features/controller_specs/Cookies.md +0 -57
  51. data/features/controller_specs/README.md +0 -45
  52. data/features/controller_specs/anonymous_controller.feature +0 -436
  53. data/features/controller_specs/bypass_rescue.feature +0 -75
  54. data/features/controller_specs/controller_spec.feature +0 -58
  55. data/features/controller_specs/engine_routes.feature +0 -51
  56. data/features/controller_specs/isolation_from_views.feature +0 -87
  57. data/features/controller_specs/render_views.feature +0 -114
  58. data/features/directory_structure.feature +0 -71
  59. data/features/feature_specs/feature_spec.feature +0 -35
  60. data/features/helper_specs/helper_spec.feature +0 -122
  61. data/features/mailer_specs/url_helpers.feature +0 -38
  62. data/features/matchers/README.md +0 -18
  63. data/features/matchers/new_record_matcher.feature +0 -41
  64. data/features/matchers/redirect_to_matcher.feature +0 -40
  65. data/features/matchers/relation_match_array.feature +0 -27
  66. data/features/matchers/render_template_matcher.feature +0 -49
  67. data/features/mocks/mock_model.feature +0 -147
  68. data/features/mocks/stub_model.feature +0 -58
  69. data/features/model_specs/README.md +0 -21
  70. data/features/model_specs/errors_on.feature +0 -51
  71. data/features/model_specs/records.feature +0 -27
  72. data/features/model_specs/transactional_examples.feature +0 -109
  73. data/features/request_specs/request_spec.feature +0 -49
  74. data/features/routing_specs/README.md +0 -16
  75. data/features/routing_specs/be_routable_matcher.feature +0 -80
  76. data/features/routing_specs/engine_routes.feature +0 -38
  77. data/features/routing_specs/named_routes.feature +0 -18
  78. data/features/routing_specs/route_to_matcher.feature +0 -90
  79. data/features/step_definitions/additional_cli_steps.rb +0 -4
  80. data/features/step_definitions/model_steps.rb +0 -3
  81. data/features/support/capybara.rb +0 -7
  82. data/features/support/env.rb +0 -53
  83. data/features/support/rails_versions.rb +0 -4
  84. data/features/support/rubinius.rb +0 -6
  85. data/features/view_specs/inferred_controller_path.feature +0 -45
  86. data/features/view_specs/stub_template.feature +0 -51
  87. data/features/view_specs/view_spec.feature +0 -206
  88. data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
  89. data/lib/rspec/rails/mocks.rb +0 -272
  90. data/lib/rspec/rails/vendor/webrat.rb +0 -33
  91. data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
  92. data/spec/generators/rspec/feature/feature_generator_spec.rb +0 -43
  93. data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
  94. data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
  95. data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -32
  96. data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
  97. data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
  98. data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
  99. data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -138
  100. data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
  101. data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
  102. data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
  103. data/spec/rspec/rails/configuration_spec.rb +0 -26
  104. data/spec/rspec/rails/deprecations_spec.rb +0 -18
  105. data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -159
  106. data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
  107. data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -66
  108. data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
  109. data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
  110. data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
  111. data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
  112. data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
  113. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
  114. data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
  115. data/spec/rspec/rails/fixture_support_spec.rb +0 -17
  116. data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
  117. data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
  118. data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
  119. data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -73
  120. data/spec/rspec/rails/matchers/has_spec.rb +0 -29
  121. data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
  122. data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -81
  123. data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
  124. data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
  125. data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
  126. data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -400
  127. data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
  128. data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
  129. data/spec/rspec/rails/view_rendering_spec.rb +0 -111
  130. data/spec/spec_helper.rb +0 -33
  131. data/spec/support/ar_classes.rb +0 -42
  132. data/spec/support/helpers.rb +0 -34
  133. data/spec/support/matchers.rb +0 -9
  134. data/spec/support/null_object.rb +0 -6
@@ -1,154 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "stub_model" do
4
-
5
- shared_examples_for "stub model" do
6
- describe "with a block" do
7
- it "yields the model" do
8
- model = stub_model(model_class) do |block_arg|
9
- @block_arg = block_arg
10
- end
11
- expect(model).to be(@block_arg)
12
- end
13
- end
14
-
15
- describe "#persisted?" do
16
- context "default" do
17
- it "returns true" do
18
- model = stub_model(model_class)
19
- expect(model).to be_persisted
20
- end
21
- end
22
-
23
- context "with as_new_record" do
24
- it "returns false" do
25
- model = stub_model(model_class).as_new_record
26
- expect(model).not_to be_persisted
27
- end
28
- end
29
- end
30
-
31
- it "increments the value returned by to_param" do
32
- first = stub_model(model_class)
33
- second = stub_model(model_class)
34
- expect(second.to_param.to_i).to eq(first.to_param.to_i + 1)
35
- end
36
-
37
- describe "#blank?" do
38
- it "is false" do
39
- expect(stub_model(model_class)).not_to be_blank
40
- end
41
- end
42
- end
43
-
44
- context "with ActiveModel (not ActiveRecord)" do
45
- it_behaves_like "stub model" do
46
- def model_class
47
- NonActiveRecordModel
48
- end
49
- end
50
- end
51
-
52
- context "with an ActiveRecord model" do
53
- let(:model_class) { MockableModel }
54
-
55
- it_behaves_like "stub model"
56
-
57
- describe "#new_record?" do
58
- context "default" do
59
- it "returns false" do
60
- model = stub_model(model_class)
61
- expect(model.new_record?).to be_falsey
62
- end
63
- end
64
-
65
- context "with as_new_record" do
66
- it "returns true" do
67
- model = stub_model(model_class).as_new_record
68
- expect(model.new_record?).to be_truthy
69
- end
70
- end
71
- end
72
-
73
- describe "defaults" do
74
- it "has an id" do
75
- expect(stub_model(MockableModel).id).to be > 0
76
- end
77
-
78
- it "says it is not a new record" do
79
- expect(stub_model(MockableModel)).not_to be_new_record
80
- end
81
- end
82
-
83
- describe "#as_new_record" do
84
- it "has a nil id" do
85
- expect(stub_model(MockableModel).as_new_record.id).to be(nil)
86
- end
87
- end
88
-
89
- it "raises when hitting the db" do
90
- expect do
91
- stub_model(MockableModel).connection
92
- end.to raise_error(RSpec::Rails::IllegalDataAccessException, /stubbed models are not allowed to access the database/)
93
- end
94
-
95
- it "increments the id" do
96
- first = stub_model(model_class)
97
- second = stub_model(model_class)
98
- expect(second.id).to eq(first.id + 1)
99
- end
100
-
101
- it "accepts a stub id" do
102
- expect(stub_model(MockableModel, :id => 37).id).to eq(37)
103
- end
104
-
105
- it "says it is a new record when id is set to nil" do
106
- expect(stub_model(MockableModel, :id => nil)).to be_new_record
107
- end
108
-
109
- it "accepts a stub for save" do
110
- expect(stub_model(MockableModel, :save => false).save).to be(false)
111
- end
112
-
113
- describe "alternate primary key" do
114
- it "has the correct primary_key name" do
115
- expect(stub_model(AlternatePrimaryKeyModel).class.primary_key.to_s).to eq('my_id')
116
- end
117
-
118
- it "has a primary_key" do
119
- expect(stub_model(AlternatePrimaryKeyModel).my_id).to be > 0
120
- end
121
-
122
- it "says it is not a new record" do
123
- stub_model(AlternatePrimaryKeyModel) do |m|
124
- expect(m).not_to be_new_record
125
- end
126
- end
127
-
128
- it "says it is a new record if primary_key is nil" do
129
- expect(stub_model(AlternatePrimaryKeyModel, :my_id => nil)).to be_new_record
130
- end
131
-
132
- it "accepts a stub for the primary_key" do
133
- expect(stub_model(AlternatePrimaryKeyModel, :my_id => 5).my_id).to eq(5)
134
- end
135
- end
136
-
137
- describe "as association" do
138
- before(:each) do
139
- @real = AssociatedModel.create!
140
- @stub_model = stub_model(MockableModel)
141
- @real.mockable_model = @stub_model
142
- end
143
-
144
- it "passes associated_model == mock" do
145
- expect(@stub_model).to eq(@real.mockable_model)
146
- end
147
-
148
- it "passes mock == associated_model" do
149
- expect(@real.mockable_model).to eq(@stub_model)
150
- end
151
- end
152
-
153
- end
154
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RSpec::Rails::SetupAndTeardownAdapter do
4
- describe "::setup" do
5
- it "registers before hooks in the order setup is received" do
6
- klass = Class.new do
7
- include RSpec::Rails::SetupAndTeardownAdapter
8
- def self.foo; "foo"; end
9
- def self.bar; "bar"; end
10
- end
11
- expect(klass).to receive(:before).ordered { |&block| expect(block.call).to eq "foo" }
12
- expect(klass).to receive(:before).ordered { |&block| expect(block.call).to eq "bar" }
13
-
14
- klass.setup :foo
15
- klass.setup :bar
16
- end
17
-
18
- it "registers prepend_before hooks for the Rails' setup methods" do
19
- klass = Class.new do
20
- include RSpec::Rails::SetupAndTeardownAdapter
21
- def self.setup_fixtures; "setup fixtures" end
22
- def self.setup_controller_request_and_response; "setup controller" end
23
- end
24
-
25
- expect(klass).to receive(:prepend_before) { |&block| expect(block.call).to eq "setup fixtures" }
26
- expect(klass).to receive(:prepend_before) { |&block| expect(block.call).to eq "setup controller" }
27
-
28
- klass.setup :setup_fixtures
29
- klass.setup :setup_controller_request_and_response
30
- end
31
- end
32
- end
@@ -1,111 +0,0 @@
1
- require "spec_helper"
2
-
3
- module RSpec::Rails
4
- describe ViewRendering do
5
- let(:group) do
6
- RSpec::Core::ExampleGroup.describe do
7
- def controller
8
- ActionController::Base.new
9
- end
10
- include ViewRendering
11
- end
12
- end
13
-
14
- context "default" do
15
- context "ActionController::Base" do
16
- it "does not render views" do
17
- expect(group.new.render_views?).to be_falsey
18
- end
19
-
20
- it "does not render views in a nested group" do
21
- expect(group.describe{}.new.render_views?).to be_falsey
22
- end
23
- end
24
-
25
- context "ActionController::Metal" do
26
- it "renders views" do
27
- group.new.tap do |example|
28
- def example.controller
29
- ActionController::Metal.new
30
- end
31
- expect(example.render_views?).to be_truthy
32
- end
33
- end
34
- end
35
- end
36
-
37
- describe "#render_views" do
38
- context "with no args" do
39
- it "tells examples to render views" do
40
- group.render_views
41
- expect(group.new.render_views?).to be_truthy
42
- end
43
- end
44
-
45
- context "with true" do
46
- it "tells examples to render views" do
47
- group.render_views true
48
- expect(group.new.render_views?).to be_truthy
49
- end
50
- end
51
-
52
- context "with false" do
53
- it "tells examples not to render views" do
54
- group.render_views false
55
- expect(group.new.render_views?).to be_falsey
56
- end
57
-
58
- it "overrides the global config if render_views is enabled there" do
59
- allow(RSpec.configuration).to receive(:render_views?).and_return true
60
- group.render_views false
61
- expect(group.new.render_views?).to be_falsey
62
- end
63
- end
64
-
65
- context "in a nested group" do
66
- let(:nested_group) do
67
- group.describe{}
68
- end
69
-
70
- context "with no args" do
71
- it "tells examples to render views" do
72
- nested_group.render_views
73
- expect(nested_group.new.render_views?).to be_truthy
74
- end
75
- end
76
-
77
- context "with true" do
78
- it "tells examples to render views" do
79
- nested_group.render_views true
80
- expect(nested_group.new.render_views?).to be_truthy
81
- end
82
- end
83
-
84
- context "with false" do
85
- it "tells examples not to render views" do
86
- nested_group.render_views false
87
- expect(nested_group.new.render_views?).to be_falsey
88
- end
89
- end
90
-
91
- it "leaves the parent group as/is" do
92
- group.render_views
93
- nested_group.render_views false
94
- expect(group.new.render_views?).to be_truthy
95
- end
96
-
97
- it "overrides the value inherited from the parent group" do
98
- group.render_views
99
- nested_group.render_views false
100
- expect(nested_group.new.render_views?).to be_falsey
101
- end
102
-
103
- it "passes override to children" do
104
- group.render_views
105
- nested_group.render_views false
106
- expect(nested_group.describe{}.new.render_views?).to be_falsey
107
- end
108
- end
109
- end
110
- end
111
- end
data/spec/spec_helper.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'rails/all'
2
-
3
- module RSpecRails
4
- class Application < ::Rails::Application
5
- self.config.secret_key_base = 'ASecretString' if config.respond_to? :secret_key_base
6
- end
7
- end
8
-
9
- require 'rspec/rails'
10
- require 'ammeter/init'
11
-
12
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
-
14
- class RSpec::Core::ExampleGroup
15
- def self.run_all(reporter=nil)
16
- run(reporter || RSpec::Mocks::Mock.new('reporter').as_null_object)
17
- end
18
- end
19
-
20
- RSpec.configure do |config|
21
- config.filter_run :focus
22
- config.run_all_when_everything_filtered = true
23
- config.order = :random
24
-
25
- real_world = nil
26
- config.before(:each) do
27
- real_world = RSpec.world
28
- RSpec.instance_variable_set(:@world, RSpec::Core::World.new)
29
- end
30
- config.after(:each) do
31
- RSpec.instance_variable_set(:@world, real_world)
32
- end
33
- end
@@ -1,42 +0,0 @@
1
- ActiveRecord::Base.establish_connection(
2
- :adapter => 'sqlite3',
3
- :database => ':memory:'
4
- )
5
-
6
- module Connections
7
- def self.extended(host)
8
- host.connection.execute <<-eosql
9
- CREATE TABLE #{host.table_name} (
10
- #{host.primary_key} integer PRIMARY KEY AUTOINCREMENT,
11
- associated_model_id integer,
12
- mockable_model_id integer,
13
- nonexistent_model_id integer
14
- )
15
- eosql
16
- end
17
- end
18
-
19
- class NonActiveRecordModel
20
- extend ActiveModel::Naming
21
- include ActiveModel::Conversion
22
- end
23
-
24
- class MockableModel < ActiveRecord::Base
25
- extend Connections
26
- has_one :associated_model
27
- end
28
-
29
- class SubMockableModel < MockableModel
30
- end
31
-
32
- class AssociatedModel < ActiveRecord::Base
33
- extend Connections
34
- belongs_to :mockable_model
35
- belongs_to :nonexistent_model, :class_name => "Other"
36
- end
37
-
38
- class AlternatePrimaryKeyModel < ActiveRecord::Base
39
- self.primary_key = :my_id
40
- extend Connections
41
- attr_accessor :my_id
42
- end
@@ -1,34 +0,0 @@
1
- module Helpers
2
- def stub_metadata(additional_metadata)
3
- stub_metadata = metadata_with(additional_metadata)
4
- allow(RSpec::Core::ExampleGroup).to receive(:metadata) { stub_metadata }
5
- end
6
-
7
- def metadata_with(additional_metadata)
8
- m = RSpec::Core::Metadata.new
9
- m.process("example group")
10
-
11
- group_metadata = additional_metadata.delete(:example_group)
12
- if group_metadata
13
- m[:example_group].merge!(group_metadata)
14
- end
15
- m.merge!(additional_metadata)
16
- m
17
- end
18
-
19
- def with_isolated_config
20
- original_config = RSpec.configuration
21
- RSpec.configuration = RSpec::Core::Configuration.new
22
- RSpec.configure do |c|
23
- c.include RSpec::Rails::FixtureSupport
24
- c.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples
25
- c.add_setting :use_instantiated_fixtures
26
- c.add_setting :global_fixtures
27
- c.add_setting :fixture_path
28
- end
29
- yield
30
- RSpec.configuration = original_config
31
- end
32
-
33
- RSpec.configure {|c| c.include self}
34
- end
@@ -1,9 +0,0 @@
1
- RSpec::Matchers::define :be_included_in_files_in do |path|
2
- match do |mod|
3
- stub_metadata(
4
- :example_group => {:file_path => "#{path}whatever_spec.rb:15"}
5
- )
6
- group = RSpec::Core::ExampleGroup.describe
7
- group.included_modules.include?(mod)
8
- end
9
- end
@@ -1,6 +0,0 @@
1
- class NullObject
2
- private
3
-
4
- def method_missing(method, *args, &blk)
5
- end
6
- end