• RSpec 的 controller spec at 2018年01月18日
    $ rake routes | grep example
    example1_example2_index GET  /example1/:example1_id/example2(.:format) example1/example2#index
                     POST /example1/:example1_id/example2(.:format) example1/example2#create
    example2 GET  /example2/:id(.:format)                   example1/example2#show
                     PATCH  /example2/:id(.:format)                   example1/example2#update
                     PUT    /example2/:id(.:format)                   example1/example2#update
                     DELETE /example2/:id(.:format)                   example1/example2#destroy
    example1_index GET    /example1(.:format)                       example1#index
    

    https://stackoverflow.com/questions/37399068/rspec-controller-for-nested-resources-before-action

    测试show action时 应该没有example1, hmmm我再查查

  • @Rei 额,惊动了您,您说的对,搞定了。

    @davidwei 您说的对,确实后面描述地不真实。。

    @hw676018683 谢谢,劳烦了。。

    比特比为大家存着了🤓 🤓

  • 真的是睡不着啊,离奇。是什么造成的呢?。。。

  • @davidwei @hw676018683 朋友们 是不是很神奇。。 我用binding.pry了,测试的时候的确是先require_admin的。。。 ruby (= 2.1.2) rails (= 4.1.1) rspec-rails (= 2.99)

    1) Admin::VideosController GET #new behaves like requires sign in redirects to sign in path
        Failure/Error: action
        NoMethodError:
          undefined method `admin?' for nil:NilClass
        Shared Example Group: "requires sign in" called from ./spec/controllers/admin/videos_controller_spec.rb:5
        # ./app/controllers/admins_controller.rb:7:in `require_admin'
        # ./spec/controllers/admin/videos_controller_spec.rb:6:in `block (4 levels) in <top (required)>'
        # ./spec/support/shared_example.rb:3:in `block (2 levels) in <top (required)>'
    
     2) Admin::VideosController POST #create behaves like requires sign in redirects to sign in path
        Failure/Error: action
        NoMethodError:
          undefined method `admin?' for nil:NilClass
        Shared Example Group: "requires sign in" called from ./spec/controllers/admin/videos_controller_spec.rb:15
        # ./app/controllers/admins_controller.rb:7:in `require_admin'
        # ./spec/controllers/admin/videos_controller_spec.rb:16:in `block (4 levels) in <top (required)>'
        # ./spec/support/shared_example.rb:3:in `block (2 levels) in <top (required)>'
     Finished in 19.17 seconds
     180 examples, 2 failures
    
  • 可以悬赏么?一个比特币。。

  • 朋友,建议你可以看一下排版说明,保证你发的内容可以正确换行,比如用三个“`” 😄 。这个问题我没太看明白

  • 刚刚在浏览器上在没有登陆的情况下手动输入http://localhost:3000/videos/new, 是先触发的require_user....可是为什么测试时顺序颠倒呢?测试是这样的

    describe Admin::VideosController, :type => :controller do
      describe "GET #new" do
        it_behaves_like "requires sign in" do
          let(:action) { get :new }
        end
      end
    end
    -------
    RSpec.shared_examples "requires sign in" do
      it "redirects to sign in path" do
        action
        expect(response).to redirect_to sign_in_path
      end
    end
    
  • Ruby 2.5.0 已发布 at 2018年01月04日

    🤓 🤓 🤓

  • Ruby 2.5.0 已发布 at 2018年01月03日

    第一次经历新版本更新,这种感觉就是像苹果发布新电脑一样的感觉吗?

  • 这就变成一个用ruby怎么删除array里其中一个元素的问题了对吗?