-
-
Notifications
You must be signed in to change notification settings - Fork 910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using the route matcher with 'format' can lead to failing specs, while everything is correct #809
Comments
👍 |
I have the same problem. I thought I can fix it with EDIT: actually you don't have to use and then |
This seems to be introduced by 15359eb. I can't see where the format being a symbol requirement is documented, should we revert that commit? /cc @maurogeorge |
I think you're right, and I would agree that we should not be symbolizing the |
+1 I'm affected by the same problem. Tests are being skipped while waiting for a solution. |
For those waiting for fix - just put this Shoulda::Matchers::ActionController::RouteParams::PARAMS_TO_SYMBOLIZE = [] into |
If that works, would that be sufficient for a pull request? |
@aried3r no, the whole thing is useless then
|
That's what I meant, can we remove it and be good? |
You might try: Shoulda::Matchers::ActionController::RouteParams.class_eval do
def symbolize_or_stringify(key, value)
if key.in?(PARAMS_TO_SYMBOLIZE)
value
else
stringify(value)
end
end
end |
Hi, I work on a new team, this team still use rails 4.1.16. I got follow error: # config/routes
namespace :dingding_crm, defaults: { format: :json } do
resources :specialists, only: [:show]
end
end Following spec is failed require 'rails_helper'
RSpec.describe Api::DingdingCrm::SpecialistsController, type: :controller do
it '' do
should route(:get, 'api/dingding_crm/specialists/100')
.to(action: :show, id: 100, format: :json)
end
end Error logs: Failure/Error: should route(:get, 'api/dingding_crm/specialists/100')
The recognized options <{"format"=>:json, "action"=>"show", "controller"=>"api/dingding_crm/specialists", "id"=>"100"}> did not match <{"action"=>"show", "id"=>"100", "format"=>"json", "controller"=>"api/dingding_crm/specialists"}>, difference:.
--- expected
+++ actual
@@ -1 +1 @@
-{"action"=>"show", "id"=>"100", "format"=>"json", "controller"=>"api/dingding_crm/specialists"}
+{"format"=>:json, "action"=>"show", "controller"=>"api/dingding_crm/specialists", "id"=>"100"} I have to workaround this with change namespace :dingding_crm, defaults: { format: 'json' } do
resources :specialists, only: [:show]
end
end This is worked again. so, this issue still exists, right? following is version: ╰─ $ 1 bundle list |grep shoulda
* shoulda (3.5.0)
* shoulda-context (1.2.2)
* shoulda-matchers (2.8.0) |
@zw963 You're using an older version of shoulda-matchers, it looks like. What happens if you upgrade to 3.1.2? |
@mcmire , hi, I have to development on a very old project (rails 4.1.16) I only add gem 'shoulda'
gem 'shoulda-matchers' into Gemfile in recent days, those version seem like is the suitable version manage by bundler. |
@zw963 We do still support Rails 4.1, but I guess upgrading wouldn't help in this case, so I'm not sure why I said that :) I thought I had fixed this problem somewhere along the way but I guess I haven't yet. Sorry about that. Your "fix" to routes.rb seems like the right move. |
@mcmire , so, there is no plan to try fix this for Rails 4.1, right ? |
@zw963 If it only shows up under Rails 4.1, then we won't be addressing it, but, I'm thinking that this problem may exist under other Rails versions, and if that's the case, then you would get this fix for free. |
AFAIK it hasn't been fixed yet. And probably never will be as there is a ton of PRs and no activity in repository. |
@istana Hey, I don't really appreciate your comments. Let's try to keep it civil around here. Thanks. |
@mcmire , I tried in my another project, which is Following is my route: namespace :wx_mini_api, path: '' do
namespace :v1, defaults: {format: :json} do
resources :items, only: [:show, :index]
end
end Following is my test: (minitest) class WxMiniApi::V1::ItemsControllerTest < ActionDispatch::IntegrationTest
should route(get: 'items').to(action: :index, format: :json)
end But I got following error: ╰─ $ 1 rails test /home/zw963/Xthink/ershou_web/test/controllers/wx_mini_api/v1/items_controller_test.rb
Running via Spring preloader in process 27342
/home/zw963/Xthink/ershou_web/test/controllers/wx_mini_api/v1/items_controller_test.rb:4:in `<class:ItemsControllerTest>': undefined method `route' for WxMiniApi::V1::ItemsControllerTest:Class (NoMethodError)
from /home/zw963/Xthink/ershou_web/test/controllers/wx_mini_api/v1/items_controller_test.rb:3:in `<top (required)>'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in `require'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in `block in require'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:258:in `load_dependency'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in `require'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/railties-5.1.1/lib/rails/test_unit/test_requirer.rb:14:in `block in require_files'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/railties-5.1.1/lib/rails/test_unit/test_requirer.rb:13:in `each'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/railties-5.1.1/lib/rails/test_unit/test_requirer.rb:13:in `require_files'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/railties-5.1.1/lib/rails/test_unit/minitest_plugin.rb:96:in `plugin_rails_init'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/minitest-5.10.3/lib/minitest.rb:81:in `block in init_plugins'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/minitest-5.10.3/lib/minitest.rb:79:in `each'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/minitest-5.10.3/lib/minitest.rb:79:in `init_plugins'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/minitest-5.10.3/lib/minitest.rb:130:in `run'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/railties-5.1.1/lib/rails/test_unit/minitest_plugin.rb:77:in `run'
from /home/zw963/.rvm/gems/ruby-2.3.3@ershou_web/gems/minitest-5.10.3/lib/minitest.rb:63:in `block in autorun'
from /home/zw963/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/zw963/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>' Following is shoulda version. ╰─ $ bundle list |grep shoulda
* shoulda (3.5.0)
* shoulda-context (1.2.2)
* shoulda-matchers (2.8.0) |
@zw963 Sigh... I'm sorry. |
@mcmire,I don't understood what you means,this new rails 5.1.1 i use minitest. |
@mcmire I'm sorry for my reaction. I really appreciate the work you do here. In my case it didn't work in Rails 4.2 either, but with shoulda matchers 2.8.0. I could try to trigger the bug with latest Rails 5.1 and shoulda matchers. |
Fixed this by just changing my routes. namespace :api, defaults: { format: 'json' } do to namespace :api, defaults: { format: :json } do |
Hey folks. In an effort to lighten our load as maintainers and be able to serve you better in the future, the shoulda-matchers team is working on cleaning out the cobwebs in this repo by pruning the backlog. As there are few of us, there are a lot of items that will simply never earn our attention in a reasonable time frame, and rather than giving you an empty promise, we think it makes more sense to focus on more recent issues. That means, unfortunately, that we must close this issue. Don't take this the wrong way: our aim is not to diminish the effort people have made or dismiss problems that have been raised. If you feel that we should reopen this issue, then please let us know so that we can reprioritize it. Thanks! |
When having a route, or namespace like this:
and trying to assert this behavior using the
route
shoulda-matcherthe spec will fail with something like:
because the matcher will try to match the symbol (spec) against a string (
route.rb
).See #693 for more details.
The text was updated successfully, but these errors were encountered: