shoulda-matchers 2.7.0 → 2.8.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -3
- data/Appraisals +18 -0
- data/CONTRIBUTING.md +13 -29
- data/Gemfile +1 -4
- data/Gemfile.lock +2 -10
- data/NEWS.md +100 -14
- data/README.md +62 -58
- data/Rakefile +9 -16
- data/gemfiles/3.0.gemfile +11 -12
- data/gemfiles/3.0.gemfile.lock +15 -10
- data/gemfiles/3.1.gemfile +11 -12
- data/gemfiles/3.1.gemfile.lock +14 -10
- data/gemfiles/3.1_1.9.2.gemfile +12 -11
- data/gemfiles/3.1_1.9.2.gemfile.lock +14 -3
- data/gemfiles/3.2.gemfile +11 -12
- data/gemfiles/3.2.gemfile.lock +15 -10
- data/gemfiles/3.2_1.9.2.gemfile +12 -11
- data/gemfiles/3.2_1.9.2.gemfile.lock +14 -2
- data/gemfiles/4.0.0.gemfile +10 -12
- data/gemfiles/4.0.0.gemfile.lock +13 -10
- data/gemfiles/4.0.1.gemfile +10 -12
- data/gemfiles/4.0.1.gemfile.lock +13 -10
- data/gemfiles/4.1.gemfile +13 -15
- data/gemfiles/4.1.gemfile.lock +45 -50
- data/gemfiles/4.2.gemfile +36 -0
- data/gemfiles/4.2.gemfile.lock +245 -0
- data/lib/shoulda/matchers.rb +3 -1
- data/lib/shoulda/matchers/action_controller.rb +1 -1
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/route_params.rb +9 -4
- data/lib/shoulda/matchers/action_controller/{set_the_flash_matcher.rb → set_flash_matcher.rb} +34 -26
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +125 -69
- data/lib/shoulda/matchers/active_model.rb +1 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +18 -5
- data/lib/shoulda/matchers/active_model/exception_message_finder.rb +2 -2
- data/lib/shoulda/matchers/active_model/helpers.rb +4 -4
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +10 -3
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +3 -1
- data/lib/shoulda/matchers/active_model/{ensure_length_of_matcher.rb → validate_length_of_matcher.rb} +30 -20
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +21 -0
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -2
- data/lib/shoulda/matchers/active_record.rb +2 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +96 -2
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +3 -3
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +22 -2
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +30 -4
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +19 -3
- data/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
- data/lib/shoulda/matchers/active_record/uniqueness/model.rb +45 -0
- data/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +36 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +50 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +24 -0
- data/lib/shoulda/matchers/{active_model → active_record}/validate_uniqueness_of_matcher.rb +76 -16
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +117 -51
- data/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +1 -1
- data/lib/shoulda/matchers/matcher_context.rb +35 -0
- data/lib/shoulda/matchers/rails_shim.rb +23 -0
- data/lib/shoulda/matchers/util.rb +28 -0
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/SUPPORTED_VERSIONS +1 -1
- data/spec/acceptance/active_model_integration_spec.rb +20 -0
- data/spec/acceptance/independent_matchers_spec.rb +64 -0
- data/spec/acceptance/rails_integration_spec.rb +142 -0
- data/spec/acceptance_spec_helper.rb +23 -0
- data/spec/support/acceptance/helpers.rb +29 -0
- data/spec/support/acceptance/helpers/active_model_helpers.rb +11 -0
- data/spec/support/acceptance/helpers/array_helpers.rb +13 -0
- data/spec/support/acceptance/helpers/base_helpers.rb +14 -0
- data/spec/support/acceptance/helpers/command_helpers.rb +51 -0
- data/spec/support/acceptance/helpers/file_helpers.rb +19 -0
- data/spec/support/acceptance/helpers/gem_helpers.rb +31 -0
- data/spec/support/acceptance/helpers/minitest_helpers.rb +19 -0
- data/spec/support/acceptance/helpers/pluralization_helpers.rb +13 -0
- data/spec/support/acceptance/helpers/rails_version_helpers.rb +11 -0
- data/spec/support/acceptance/helpers/rspec_helpers.rb +26 -0
- data/spec/support/acceptance/helpers/ruby_version_helpers.rb +9 -0
- data/spec/support/acceptance/helpers/step_helpers.rb +117 -0
- data/spec/support/acceptance/matchers/have_output.rb +31 -0
- data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +55 -0
- data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +103 -0
- data/spec/support/tests/bundle.rb +94 -0
- data/spec/support/tests/command_runner.rb +214 -0
- data/spec/support/tests/filesystem.rb +77 -0
- data/spec/support/tests/version.rb +45 -0
- data/spec/support/unit/capture.rb +34 -0
- data/spec/support/unit/helpers/active_model_helpers.rb +25 -0
- data/spec/support/unit/helpers/active_model_versions.rb +20 -0
- data/spec/support/unit/helpers/active_resource_builder.rb +27 -0
- data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +15 -0
- data/spec/support/unit/helpers/class_builder.rb +72 -0
- data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +17 -0
- data/spec/support/unit/helpers/controller_builder.rb +91 -0
- data/spec/support/unit/helpers/i18n_faker.rb +15 -0
- data/spec/support/unit/helpers/mailer_builder.rb +12 -0
- data/spec/support/unit/helpers/model_builder.rb +102 -0
- data/spec/support/unit/helpers/rails_versions.rb +28 -0
- data/spec/support/unit/i18n.rb +7 -0
- data/spec/support/unit/matchers/deprecate.rb +60 -0
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +50 -0
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +50 -0
- data/spec/support/unit/matchers/print_warning_including.rb +59 -0
- data/spec/support/unit/rails_application.rb +110 -0
- data/spec/support/unit/record_builder_with_i18n_validation_message.rb +69 -0
- data/spec/support/unit/record_validating_confirmation_builder.rb +56 -0
- data/spec/support/unit/record_with_different_error_attribute_builder.rb +92 -0
- data/spec/support/{shared_examples → unit/shared_examples}/numerical_submatcher.rb +0 -2
- data/spec/support/{shared_examples → unit/shared_examples}/numerical_type_submatcher.rb +0 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/callback_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/filter_param_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/redirect_to_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_template_matcher_spec.rb +2 -4
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_with_layout_matcher_spec.rb +9 -6
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/rescue_from_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/respond_with_matcher_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +126 -0
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/route_params_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +167 -0
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +294 -0
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/strong_parameters_matcher_spec.rb +19 -11
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_value_matcher_spec.rb +49 -21
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/disallow_value_matcher_spec.rb +8 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/exception_message_finder_spec.rb +4 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/have_secure_password_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/helpers_spec.rb +7 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_absence_of_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_acceptance_of_matcher_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +63 -0
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_exclusion_of_matcher_spec.rb +5 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_inclusion_of_matcher_spec.rb +7 -14
- data/spec/{shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb → unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb} +43 -23
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_numericality_of_matcher_spec.rb +3 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_presence_of_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +127 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validation_message_finder_spec.rb +8 -6
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matcher_spec.rb +217 -26
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matchers/model_reflection_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/define_enum_for_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_column_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_index_matcher_spec.rb +8 -5
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_readonly_attributes_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/serialize_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_collection_spec.rb +29 -7
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_spec.rb +20 -10
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/object_double_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/proxy_implementation_spec.rb +13 -6
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/stub_implementation_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +77 -0
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak_spec.rb +11 -3
- data/spec/{shoulda → unit/shoulda}/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +517 -0
- data/spec/unit_spec_helper.rb +66 -0
- data/spec/warnings_spy/partitioner.rb +10 -3
- data/spec/warnings_spy/reader.rb +9 -20
- data/spec/warnings_spy/reporter.rb +2 -1
- metadata +212 -149
- data/features/activemodel_integration.feature +0 -15
- data/features/rails_integration.feature +0 -160
- data/features/step_definitions/activemodel_steps.rb +0 -21
- data/features/step_definitions/rails_steps.rb +0 -227
- data/features/support/env.rb +0 -6
- data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -70
- data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -113
- data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +0 -153
- data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -47
- data/spec/shoulda/matchers/doublespeak/world_spec.rb +0 -70
- data/spec/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -309
- data/spec/spec_helper.rb +0 -42
- data/spec/support/active_model_versions.rb +0 -13
- data/spec/support/active_resource_builder.rb +0 -29
- data/spec/support/activemodel_helpers.rb +0 -23
- data/spec/support/capture_helpers.rb +0 -19
- data/spec/support/class_builder.rb +0 -46
- data/spec/support/controller_builder.rb +0 -102
- data/spec/support/fail_with_message_including_matcher.rb +0 -44
- data/spec/support/fail_with_message_matcher.rb +0 -44
- data/spec/support/i18n_faker.rb +0 -10
- data/spec/support/mailer_builder.rb +0 -10
- data/spec/support/model_builder.rb +0 -81
- data/spec/support/rails_versions.rb +0 -26
- data/spec/support/test_application.rb +0 -120
@@ -1,15 +0,0 @@
|
|
1
|
-
Feature: integration with ActiveModel
|
2
|
-
|
3
|
-
Scenario: create a new project using matchers
|
4
|
-
When I generate a new ActiveModel application
|
5
|
-
And I configure the application to use "shoulda-matchers" from this project
|
6
|
-
And I write to "load_dependencies.rb" with:
|
7
|
-
"""
|
8
|
-
require 'active_model'
|
9
|
-
require 'shoulda-matchers'
|
10
|
-
|
11
|
-
puts ActiveModel::VERSION::STRING
|
12
|
-
puts "Loaded all dependencies without errors"
|
13
|
-
"""
|
14
|
-
When I successfully run `bundle exec ruby load_dependencies.rb`
|
15
|
-
Then the output should contain "Loaded all dependencies without errors"
|
@@ -1,160 +0,0 @@
|
|
1
|
-
Feature: integrate with Rails
|
2
|
-
|
3
|
-
Background:
|
4
|
-
When I generate a new rails application
|
5
|
-
And I write to "db/migrate/1_create_users.rb" with:
|
6
|
-
"""
|
7
|
-
class CreateUsers < ActiveRecord::Migration
|
8
|
-
def self.up
|
9
|
-
create_table :users do |t|
|
10
|
-
t.string :name
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
"""
|
15
|
-
When I successfully run `bundle exec rake db:migrate db:test:prepare --trace`
|
16
|
-
And I write to "app/models/user.rb" with:
|
17
|
-
"""
|
18
|
-
class User < ActiveRecord::Base
|
19
|
-
validates_presence_of :name
|
20
|
-
end
|
21
|
-
"""
|
22
|
-
When I write to "app/controllers/examples_controller.rb" with:
|
23
|
-
"""
|
24
|
-
class ExamplesController < ApplicationController
|
25
|
-
def show
|
26
|
-
@example = 'hello'
|
27
|
-
render :nothing => true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
"""
|
31
|
-
When I configure a wildcard route
|
32
|
-
|
33
|
-
Scenario: generate a rails application and use matchers in Test::Unit
|
34
|
-
When I configure the application to use shoulda-context
|
35
|
-
And I configure the application to use "shoulda-matchers" from this project
|
36
|
-
And I write to "test/unit/user_test.rb" with:
|
37
|
-
"""
|
38
|
-
require 'test_helper'
|
39
|
-
|
40
|
-
class UserTest < ActiveSupport::TestCase
|
41
|
-
should validate_presence_of(:name)
|
42
|
-
end
|
43
|
-
"""
|
44
|
-
When I write to "test/functional/examples_controller_test.rb" with:
|
45
|
-
"""
|
46
|
-
require 'test_helper'
|
47
|
-
|
48
|
-
class ExamplesControllerTest < ActionController::TestCase
|
49
|
-
def setup
|
50
|
-
get :show
|
51
|
-
end
|
52
|
-
|
53
|
-
should respond_with(:success)
|
54
|
-
end
|
55
|
-
"""
|
56
|
-
When I set the "TESTOPTS" environment variable to "-v"
|
57
|
-
When I successfully run `bundle exec rake test --trace`
|
58
|
-
Then the output should indicate that 1 unit and 1 functional test were run
|
59
|
-
And the output should contain "User should require name to be set"
|
60
|
-
And the output should contain "should respond with 200"
|
61
|
-
|
62
|
-
Scenario: generate a rails application and use matchers in Rspec
|
63
|
-
When I configure the application to use rspec-rails
|
64
|
-
And I configure the application to use "shoulda-matchers" from this project
|
65
|
-
And I run the rspec generator
|
66
|
-
And I write to "spec/models/user_spec.rb" with:
|
67
|
-
"""
|
68
|
-
require 'spec_helper'
|
69
|
-
if RSpec::Core::Version::STRING.to_i >= 3
|
70
|
-
require 'rails_helper'
|
71
|
-
end
|
72
|
-
|
73
|
-
describe User do
|
74
|
-
it { should validate_presence_of(:name) }
|
75
|
-
end
|
76
|
-
"""
|
77
|
-
When I write to "spec/controllers/examples_controller_spec.rb" with:
|
78
|
-
"""
|
79
|
-
require 'spec_helper'
|
80
|
-
if RSpec::Core::Version::STRING.to_i >= 3
|
81
|
-
require 'rails_helper'
|
82
|
-
end
|
83
|
-
|
84
|
-
describe ExamplesController, "show" do
|
85
|
-
before { get :show }
|
86
|
-
it { should respond_with(:success) }
|
87
|
-
end
|
88
|
-
"""
|
89
|
-
When I successfully run `bundle exec rake spec SPEC_OPTS=-fd --trace`
|
90
|
-
Then the output should contain "2 examples, 0 failures"
|
91
|
-
And the output should contain "should require name to be set"
|
92
|
-
And the output should contain "should respond with 200"
|
93
|
-
|
94
|
-
@spring
|
95
|
-
Scenario: A Rails application that uses RSpec, requires shoulda-matchers manually, and uses Spring to run tests
|
96
|
-
When I configure the application to use Spring
|
97
|
-
When I configure the application to use "spring-commands-rspec"
|
98
|
-
When I configure the application to use rspec-rails
|
99
|
-
And I configure the application to use "shoulda-matchers" from this project, disabling auto-require
|
100
|
-
And I run the rspec generator
|
101
|
-
And I require shoulda-matchers following rspec-rails
|
102
|
-
And I write to "spec/models/user_spec.rb" with:
|
103
|
-
"""
|
104
|
-
require 'spec_helper'
|
105
|
-
if RSpec::Core::Version::STRING.to_i >= 3
|
106
|
-
require 'rails_helper'
|
107
|
-
end
|
108
|
-
|
109
|
-
describe User do
|
110
|
-
it { should validate_presence_of(:name) }
|
111
|
-
end
|
112
|
-
"""
|
113
|
-
When I write to "spec/controllers/examples_controller_spec.rb" with:
|
114
|
-
"""
|
115
|
-
require 'spec_helper'
|
116
|
-
if RSpec::Core::Version::STRING.to_i >= 3
|
117
|
-
require 'rails_helper'
|
118
|
-
end
|
119
|
-
|
120
|
-
describe ExamplesController, "show" do
|
121
|
-
before { get :show }
|
122
|
-
it { should respond_with(:success) }
|
123
|
-
it { should_not render_template('foo') }
|
124
|
-
end
|
125
|
-
"""
|
126
|
-
When I run `bundle exec spring stop`
|
127
|
-
When I successfully run `bundle exec spring rspec spec -fd`
|
128
|
-
Then the output should contain "3 examples, 0 failures"
|
129
|
-
And the output should contain "should require name to be set"
|
130
|
-
And the output should contain "should respond with 200"
|
131
|
-
|
132
|
-
Scenario: generate a Rails application that mixes Rspec and Test::Unit
|
133
|
-
When I configure the application to use rspec-rails in test and development
|
134
|
-
And I configure the application to use "shoulda-matchers" from this project in test and development
|
135
|
-
And I run the rspec generator
|
136
|
-
And I write to "spec/models/user_spec.rb" with:
|
137
|
-
"""
|
138
|
-
require 'spec_helper'
|
139
|
-
if RSpec::Core::Version::STRING.to_i == 3
|
140
|
-
require 'rails_helper'
|
141
|
-
end
|
142
|
-
|
143
|
-
describe User do
|
144
|
-
it { should validate_presence_of(:name) }
|
145
|
-
end
|
146
|
-
"""
|
147
|
-
When I write to "test/functional/examples_controller_test.rb" with:
|
148
|
-
"""
|
149
|
-
require 'test_helper'
|
150
|
-
|
151
|
-
class ExamplesControllerTest < ActionController::TestCase
|
152
|
-
test 'responds successfully' do
|
153
|
-
get :show
|
154
|
-
assert respond_with(:success)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
"""
|
158
|
-
When I successfully run `bundle exec rake spec test:functionals SPEC_OPTS=-fd --trace`
|
159
|
-
Then the output should contain "1 example, 0 failures"
|
160
|
-
Then the output should indicate that 1 test was run
|
@@ -1,21 +0,0 @@
|
|
1
|
-
When 'I generate a new ActiveModel application' do
|
2
|
-
steps %{
|
3
|
-
When I run `mkdir #{APP_NAME}`
|
4
|
-
And I cd to "#{APP_NAME}"
|
5
|
-
And I run `bundle init`
|
6
|
-
}
|
7
|
-
|
8
|
-
# Figure out the ActiveModel version to use by reusing the Rails version from
|
9
|
-
# the Appraise gemfile.
|
10
|
-
if match = File.read(ENV['BUNDLE_GEMFILE']).match(/^gem "rails", "(.*)"/)
|
11
|
-
append_to_gemfile %(gem 'activemodel', '#{ match[1] }')
|
12
|
-
else
|
13
|
-
puts "Couldn't determine which ActiveModel version to load; using latest"
|
14
|
-
append_to_gemfile %(gem 'activemodel')
|
15
|
-
end
|
16
|
-
|
17
|
-
steps %{
|
18
|
-
And I set the "BUNDLE_GEMFILE" environment variable to "Gemfile"
|
19
|
-
And I install gems
|
20
|
-
}
|
21
|
-
end
|
@@ -1,227 +0,0 @@
|
|
1
|
-
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
|
2
|
-
APP_NAME = 'testapp'.freeze
|
3
|
-
|
4
|
-
BUNDLE_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE)
|
5
|
-
ORIGINAL_BUNDLE_VARS = Hash[ENV.select{ |key,value| BUNDLE_ENV_VARS.include?(key) }]
|
6
|
-
|
7
|
-
Before do
|
8
|
-
ENV['BUNDLE_GEMFILE'] = File.join(Dir.pwd, ENV['BUNDLE_GEMFILE']) unless ENV['BUNDLE_GEMFILE'].start_with?(Dir.pwd)
|
9
|
-
end
|
10
|
-
|
11
|
-
After do
|
12
|
-
ORIGINAL_BUNDLE_VARS.each_pair do |key, value|
|
13
|
-
ENV[key] = value
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
When 'I generate a new rails application' do
|
18
|
-
steps %{
|
19
|
-
When I run `bundle exec rails new #{APP_NAME} --skip-bundle`
|
20
|
-
And I cd to "#{APP_NAME}"
|
21
|
-
And I comment out the gem "turn" from the Gemfile
|
22
|
-
And I comment out the gem "coffee-rails" from the Gemfile
|
23
|
-
And I comment out the gem "uglifier" from the Gemfile
|
24
|
-
And I reset Bundler environment variables
|
25
|
-
And I set the "BUNDLE_GEMFILE" environment variable to "Gemfile"
|
26
|
-
And I install gems
|
27
|
-
}
|
28
|
-
|
29
|
-
if RUBY_VERSION >= '1.9.3'
|
30
|
-
append_to_gemfile %(gem 'rake', '~> 0.9')
|
31
|
-
step %(I successfully run `bundle update rake`)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
When /^I configure the application to use "([^\"]+)"$/ do |name|
|
36
|
-
append_to_gemfile "gem '#{name}'"
|
37
|
-
steps %{And I install gems}
|
38
|
-
end
|
39
|
-
|
40
|
-
When 'I configure the application to use Spring' do
|
41
|
-
if rails_lt_4?
|
42
|
-
append_to_gemfile "gem 'spring'"
|
43
|
-
steps %{And I install gems}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
|
48
|
-
append_to_gemfile "gem '#{name}', path: '#{PROJECT_ROOT}'"
|
49
|
-
steps %{And I install gems}
|
50
|
-
end
|
51
|
-
|
52
|
-
When /^I configure the application to use "([^\"]+)" from this project, disabling auto-require$/ do |name|
|
53
|
-
append_to_gemfile "gem '#{name}', path: '#{PROJECT_ROOT}', require: false"
|
54
|
-
steps %{And I install gems}
|
55
|
-
end
|
56
|
-
|
57
|
-
When /^I configure the application to use "([^\"]+)" from this project in test and development$/ do |name|
|
58
|
-
append_to_gemfile <<-GEMFILE
|
59
|
-
group :test, :development do
|
60
|
-
gem '#{name}', path: '#{PROJECT_ROOT}'
|
61
|
-
end
|
62
|
-
GEMFILE
|
63
|
-
steps %{And I install gems}
|
64
|
-
end
|
65
|
-
|
66
|
-
When 'I run the rspec generator' do
|
67
|
-
steps %{
|
68
|
-
When I successfully run `rails generate rspec:install`
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
|
-
When 'I configure the application to use rspec-rails' do
|
73
|
-
append_to_gemfile <<-GEMFILE
|
74
|
-
gem 'rspec-rails', '#{rspec_rails_version}'
|
75
|
-
GEMFILE
|
76
|
-
steps %{And I install gems}
|
77
|
-
end
|
78
|
-
|
79
|
-
When 'I configure the application to use rspec-rails in test and development' do
|
80
|
-
append_to_gemfile <<-GEMFILE
|
81
|
-
group :test, :development do
|
82
|
-
gem 'rspec-rails', '#{rspec_rails_version}'
|
83
|
-
end
|
84
|
-
GEMFILE
|
85
|
-
steps %{And I install gems}
|
86
|
-
end
|
87
|
-
|
88
|
-
When 'I configure the application to use shoulda-context' do
|
89
|
-
append_to_gemfile %q(gem 'shoulda-context', '~> 1.2.0')
|
90
|
-
append_to_gemfile %q(gem 'pry')
|
91
|
-
steps %{And I install gems}
|
92
|
-
end
|
93
|
-
|
94
|
-
When 'I require shoulda-matchers following rspec-rails' do
|
95
|
-
insert_line_after test_helper_path,
|
96
|
-
"require 'rspec/rails'",
|
97
|
-
"require 'shoulda/matchers'"
|
98
|
-
end
|
99
|
-
|
100
|
-
When /^I set the "([^"]*)" environment variable to "([^"]*)"$/ do |key, value|
|
101
|
-
ENV[key] = value
|
102
|
-
end
|
103
|
-
|
104
|
-
When 'I configure a wildcard route' do
|
105
|
-
steps %{
|
106
|
-
When I write to "config/routes.rb" with:
|
107
|
-
"""
|
108
|
-
Rails.application.routes.draw do
|
109
|
-
get ':controller(/:action(/:id(.:format)))'
|
110
|
-
end
|
111
|
-
"""
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
When 'I append gems from Appraisal Gemfile' do
|
116
|
-
File.read(ENV['BUNDLE_GEMFILE']).split("\n").each do |line|
|
117
|
-
if line =~ /^gem "(?!rails|appraisal)/
|
118
|
-
append_to_gemfile line.strip
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
When 'I reset Bundler environment variables' do
|
124
|
-
BUNDLE_ENV_VARS.each do |key|
|
125
|
-
ENV[key] = nil
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
|
130
|
-
comment_out_gem_in_gemfile(gemname)
|
131
|
-
end
|
132
|
-
|
133
|
-
When /^I install gems$/ do
|
134
|
-
steps %{When I run `bundle install --local`}
|
135
|
-
end
|
136
|
-
|
137
|
-
Then /^the output should indicate that (\d+) tests? (?:was|were) run/ do |number|
|
138
|
-
# Rails 4 has slightly different output than Rails 3 due to
|
139
|
-
# Test::Unit::TestCase -> MiniTest
|
140
|
-
if rails_lt_4?
|
141
|
-
steps %{Then the output should contain "#{number} tests, #{number} assertions, 0 failures, 0 errors"}
|
142
|
-
else
|
143
|
-
steps %{Then the output should match /#{number} (tests|runs), #{number} assertions, 0 failures, 0 errors, 0 skips/}
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
Then /^the output should indicate that (\d+) unit and (\d+) functional tests? were run/ do |n1, n2|
|
148
|
-
n1 = n1.to_i
|
149
|
-
n2 = n2.to_i
|
150
|
-
total = n1.to_i + n2.to_i
|
151
|
-
# Rails 3 runs separate test suites in separate processes, but Rails 4 does
|
152
|
-
# not, so that's why we have to check for different things here
|
153
|
-
if rails_lt_4?
|
154
|
-
steps %{Then the output should match /#{n1} tests, #{n1} assertions, 0 failures, 0 errors.+#{n2} tests, #{n2} assertions, 0 failures, 0 errors/}
|
155
|
-
else
|
156
|
-
steps %{Then the output should match /#{total} (tests|runs), #{total} assertions, 0 failures, 0 errors, 0 skips/}
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
module FileHelpers
|
161
|
-
RAILS_VERSION_IN_GEMFILE_PATH_REGEX = %r{/([^/]+?)(?:_.+)?\.gemfile$}
|
162
|
-
|
163
|
-
def append_to(path, contents)
|
164
|
-
in_current_dir do
|
165
|
-
File.open(path, 'a') do |file|
|
166
|
-
file.puts
|
167
|
-
file.puts contents
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def append_to_gemfile(contents)
|
173
|
-
append_to('Gemfile', contents)
|
174
|
-
end
|
175
|
-
|
176
|
-
def comment_out_gem_in_gemfile(gemname)
|
177
|
-
in_current_dir do
|
178
|
-
gemfile = File.read('Gemfile')
|
179
|
-
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
|
180
|
-
File.open('Gemfile', 'w'){ |file| file.write(gemfile) }
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def insert_line_after(file_path, line, line_to_insert)
|
185
|
-
line += "\n"
|
186
|
-
line_to_insert += "\n"
|
187
|
-
|
188
|
-
in_current_dir do
|
189
|
-
contents = File.read(file_path)
|
190
|
-
index = contents.index(line) + line.length
|
191
|
-
contents.insert(index, line_to_insert)
|
192
|
-
File.open(file_path, 'w') { |f| f.write(contents) }
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
def rails_version_string
|
197
|
-
ORIGINAL_BUNDLE_VARS['BUNDLE_GEMFILE'].
|
198
|
-
match(RAILS_VERSION_IN_GEMFILE_PATH_REGEX).
|
199
|
-
captures[0]
|
200
|
-
end
|
201
|
-
|
202
|
-
def rails_version
|
203
|
-
@_rails_version ||= Gem::Version.new(rails_version_string)
|
204
|
-
end
|
205
|
-
|
206
|
-
def rails_lt_4?
|
207
|
-
Gem::Requirement.new('< 4').satisfied_by?(rails_version)
|
208
|
-
end
|
209
|
-
|
210
|
-
def rspec_rails_version
|
211
|
-
Bundler.definition.specs['rspec-rails'][0].version
|
212
|
-
end
|
213
|
-
|
214
|
-
def rspec_rails_gte_3?
|
215
|
-
Gem::Requirement.new('>= 3').satisfied_by?(rspec_rails_version)
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_helper_path
|
219
|
-
if rspec_rails_gte_3?
|
220
|
-
'spec/rails_helper.rb'
|
221
|
-
else
|
222
|
-
'spec/spec_helper.rb'
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
World(FileHelpers)
|
data/features/support/env.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Shoulda::Matchers::ActionController::RouteMatcher', type: :controller do
|
4
|
-
context 'given a controller with a defined glob url' do
|
5
|
-
it 'accepts glob route' do
|
6
|
-
controller = define_controller('Examples').new
|
7
|
-
|
8
|
-
define_routes do
|
9
|
-
get 'examples/*id', to: 'examples#example'
|
10
|
-
end
|
11
|
-
|
12
|
-
expect(controller).to route(:get, '/examples/foo/bar').
|
13
|
-
to(action: 'example', id: 'foo/bar')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'given a controller with a defined route' do
|
18
|
-
|
19
|
-
it 'accepts routing the correct path to the correct parameters' do
|
20
|
-
expect(route_examples_to_examples).to route(:get, '/examples/1').
|
21
|
-
to(action: 'example', id: '1')
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'accepts a symbol controller' do
|
25
|
-
route_examples_to_examples
|
26
|
-
expect(Object.new).to route(:get, '/examples/1').
|
27
|
-
to(controller: :examples, action: 'example', id: '1')
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'accepts a symbol action' do
|
31
|
-
expect(route_examples_to_examples).to route(:get, '/examples/1').
|
32
|
-
to(action: :example, id: '1')
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'accepts a non-string parameter' do
|
36
|
-
expect(route_examples_to_examples).to route(:get, '/examples/1').
|
37
|
-
to(action: 'example', id: 1)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'rejects an undefined route' do
|
41
|
-
expect(route_examples_to_examples).
|
42
|
-
not_to route(:get, '/bad_route').to(var: 'value')
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'rejects a route for another controller' do
|
46
|
-
route_examples_to_examples
|
47
|
-
other = define_controller('Other').new
|
48
|
-
expect(other).not_to route(:get, '/examples/1').
|
49
|
-
to(action: 'example', id: '1')
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'rejects a route for different parameters' do
|
53
|
-
expect(route_examples_to_examples).not_to route(:get, '/examples/1').
|
54
|
-
to(action: 'other', id: '1')
|
55
|
-
end
|
56
|
-
|
57
|
-
it "accepts a string as first parameter" do
|
58
|
-
expect(route_examples_to_examples).to route(:get, '/examples/1').
|
59
|
-
to("examples#example", id: '1')
|
60
|
-
end
|
61
|
-
|
62
|
-
def route_examples_to_examples
|
63
|
-
define_routes do
|
64
|
-
get 'examples/:id', to: 'examples#example'
|
65
|
-
end
|
66
|
-
|
67
|
-
define_controller('Examples').new
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|