代码之家  ›  专栏  ›  技术社区  ›  BvuRVKyUVlViVIc7

每次“www.example.com”时,即使在environments/test.rb中指定,也要使用Cucumber default_url_options[:host]

  •  5
  • BvuRVKyUVlViVIc7  · 技术社区  · 16 年前

    config.action_mailer.default_url_options = { :host => "www.xyu.at" }
    

    invitation_activation_url(1)
    => "www.xyu.at/signup/1231hj23jh23"
    

    http://github.com/bmabey/email-spec/tree/master ):

    When /^I follow the invitation link$/ do
      When 'I follow "'+invitation_activation_url(1) + '" in the email'
    end
    

    invitation_activation_url(1)
    => "www.example.com/signup/1231hj23jh23"
    

    谢谢!

    编辑:

    current_url
    

    编辑:

    我在features/support/env.rb中指定了正确的环境

    ENV["RAILS_ENV"] ||= "test"
    

    编辑:

    invitation_activation_url(1, :host => "www.xyz.at")
      => "www.xyz.at/signup/1231hj23jh23"
    

    但我不想这样明确地命名域名

    5 回复  |  直到 16 年前
        1
  •  1
  •   Ilan    14 年前

    invitation_activation_url(1, :host => "www.xyz.at")
      => "www.xyz.at/signup/1231hj23jh23"
    

    编辑:

    您可以解析电子邮件正文并获取链接

      mail = YourMailer.deliveries.last
      email_html = Nokogiri::HTML mail.body.to_s
      approve_link = email_html.at_css("a")["href"]
    
        2
  •  1
  •   edbond    13 年前

    我知道这篇文章发表已经好几年了。但我遇到了这个问题,花了几个小时才破译出来。

    When /^I follow the invitation link$/ do
      When 'I follow "'+invitation_activation_path(1) + '" in the email'
    end
    

    url生成url路径;而_ path生成URI路径。 web_steps.rb使用URI来确定用于计算主机的current_url。

    http://api.rubyonrails.org/classes/ActionDispatch/Routing.html

    URI路径的name_of_route_path。

    来自web_steps.rb

    Then /^(?:|I )should be on (.+)$/ do |page_name|                                                                                                                                     |  #     end                                                                                                                                                                           
      current_path = URI.parse(current_url).path                                                                                                                                         |  #                                                                                                                                                                                   
      if current_path.respond_to? :should                                                                                                                                                |  #     collection do                                                                                                                                                                 
        current_path.should == path_to(page_name)                                                                                                                                        |  #       get 'sold'                                                                                                                                                                  
      else                                                                                                                                                                               |  #     end                                                                                                                                                                           
        assert_equal path_to(page_name), current_path                                                                                                                                    |  #   end                                                                                                                                                                             
      end                                                                                                                                                                                |
    end 
    
        3
  •  0
  •   Jamie Flournoy    16 年前

    在我的项目的features/support/env.rb中有这样的内容:

    ENV["RAILS_ENV"] ||= "cucumber"
    

        4
  •  0
  •   webmat    16 年前

    我对Cucumber不太熟悉,所以我不能肯定地说你必须在哪里应用这个修复程序。但问题是,default_url_options没有设置在您尝试生成url的另一个地方。..

    因此,我的建议是首先找出错误网址是在什么情况下生成的。在它之前或之后,只需输出self.class。这就是你要修的课。例如,假设“ClassName”已打印出来。

    class ClassName
      cattr_accessor :default_url_options
      # or mattr_ if it's a module
    end
    

    ClassName.default_url_options = { :host => "www.xyu.at" }
    

        5
  •  0
  •   Henrik N    16 年前

    一种解决方案(基于信息 here )要有一个步骤定义,如

    Given /^the domain "(.+?)"$/ do |domain|
      host! domain
    end
    

    Given the domain "www.foo.com"
    

    this patch

    我最终在Cucumber的env.rb文件中使用了一个非常简单的解决方法:

    # There is a bug in internal_redirect? when used with explicit (non-example.com) domains.
    # This is a simple workaround but may break if we start specing external redirects.
    # https://webrat.lighthouseapp.com/projects/10503/tickets/140-current_url-should-be-fully-qualified
    class Webrat::Session
      alias internal_redirect? redirect?
    end
    

    正如评论中提到的,这当然可能会与外部重定向中断,但我们没有。