Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 如何解决“缺少主机链接到!请提供:host参数“? (ROR)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我跟着 RoR Tutorial,我被困在 Listing 9.15

运行’bundle exec rspec spec /’后,我收到以下错误:

1) Authentication authorization as wrong user submitTing a PATCH request to the Users#update action 
     Failure/Error: specify { expect(responsE).to redirect_to(root_url) }
     ArgumentError:
       Missing host to link to! Please provide the :host parameter,set default_url_options[:host],or set :only_path to true
     # ./spec/features/authentication_pages_spec.rb:79:in `block (5 levels) in <top (required)>'

我的验证测试代码是:

需要’spec_Helper’

describe "Authentication",type: :request do

  subject { page }


  describe "signin page" do
    before { visit signin_path }

    it { should have_content('Sign in') }
    it { should have_title('Sign in') }
  end

  describe "signin" do
    before { visit signin_path }

    describe "with invalid information" do
      before { click_button "Sign in" }

      it { should have_title('Sign in') }
      it { should have_SELEctor('div.alert.alert-error',text: 'Invalid') }

      describe "after visiTing another page" do
        before { click_link "Home" }
        it { should_not have_SELEctor('div.alert.alert-error') }
      end

    end

    describe "with valid information" do
      let(:user) { FactoryGirl.create(:user) }
      before { sign_in user }

      #it { should have_title(user.Name) }
      it { should have_link('Profile',href: @R_801_9004@path(user)) }
      it { should have_link('SetTings',href: edit_@R_801_9004@path(user)) }
      it { should have_link('Sign out',href: signout_path) }
      it { should_not have_link('Sign in',href: signin_path) }

      describe "followed by signout" do
        before { click_link "Sign out" }
        it { should have_link('Sign in') }
      end
    end
  end

  describe "authorization" do

    describe "for non-signed-in users" do
      let(:user) { FactoryGirl.create(:user) }

      describe "in the Users controller" do

        describe "visiTing the edit page" do
          before { visit edit_@R_801_9004@path(user) }
          it { should have_title('Sign in') }
        end

        describe "submitTing to the update action" do
          before { patch @R_801_9004@path(user) }
          specify { expect(responsE).to redirect_to(signin_path) }
        end
      end
    end

    describe "as wrong user" do
      let(:user) { FactoryGirl.create(:user) }
      let(:wrong_user) { FactoryGirl.create(:user,email: "wrong@example.com") }
      before { sign_in user,no_capybara: true }

      describe "visiTing Users#edit page" do
        before { visit edit_@R_801_9004@path(wrong_user) }
        #it { should_not have_title(full_title('Edit user')) }
      end

      describe "submitTing a PATCH request to the Users#update action" do
        before { patch @R_801_9004@path(wrong_user) }
        specify { expect(responsE).to redirect_to(root_url) }
      end
    end

  end
end

我不知道如何解决这个问题,所以测试通过.我该如何解决?有人可以解释出了什么问题吗? (根据教程测试应该通过).

解决方法

问题可能是您没有为测试环境定义default_host.在config / environments / test.rb中定义default_host,如下所示:
config.action_mailer.default_url_options = {:host => "localhost:3000"}

大佬总结

以上是大佬教程为你收集整理的ruby-on-rails – 如何解决“缺少主机链接到!请提供:host参数“? (ROR)全部内容,希望文章能够帮你解决ruby-on-rails – 如何解决“缺少主机链接到!请提供:host参数“? (ROR)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。