使用恶作剧者

时间:2017-05-26 13:35:48

标签: ruby-on-rails ruby heroku capybara poltergeist

我正在编写一个测试应用程序的rake任务。为了测试它我需要Capybara和Poltergeist。 Rake任务看起来像这样:

require "capybara"
require "capybara/poltergeist"
require "capybara/dsl"

namespace :almet do
  desc "Checking if something changed on tatar.ru"
  task check_news: :environment do
    Capybara.current_driver = :poltergeist
    Browser = Class.new { include Capybara::DSL }
    page = Browser.new.page
    page.visit("http://almetyevsk.tatar.ru")
    unless page.has_selector?(".home-events ul li") &
       page.has_selector?(".home-events__item-lead") &
       page.has_selector?(".home-events__item-date") &
       page.has_selector?("h2 a")
    then
       alert
    end
    news_link = page.find(:css, "h2 a", match: :first)[:href]
    page.visit(news_link)
    unless page.has_selector?(".page__content-i h2") &
       page.has_selector?(".page__content-i .news") &
       page.has_selector?("i")
    then
       alert
    end
  end

  def alert
    AlertMailer.alert.deliver_now
  end
end

此代码检查解析数据的主站点是否仍然相同(css选择器中没有更改)。这个rake任务在本地运行良好,但是当我把它推到heroku时我遇到了错误:

rake aborted!
Cliver::Dependency::NotFound: Could not find an executable ["phantomjs"] on your path.

我用谷歌搜索,安装了幻影,但仍然有同样的错误。(使用phantomJS的恶作剧者)。有可能解决我的问题吗?

1 个答案:

答案 0 :(得分:0)

您需要将PhantomJS安装到Heroku实例上。通常这涉及添加一个将为您安装的构建包,如https://github.com/stomita/heroku-buildpack-phantomjs

相关问题