rspec如何使用capybara查询html正文电子邮件

Vla*_*mir 2 bdd rspec ruby-on-rails actionmailer capybara

也许这是新手问题,但我被困了.我尝试用capybara查询html电子邮件,但没有运气.这是规格

# encoding: utf-8
require "spec_helper"
require "resque"
require "resque_spec"

describe 'MailerUtils in action'  do
  include MailerMacros

  let(:service_provider_email) { FactoryGirl.create(:service_provider_email) }
  let(:service_provider) { service_provider_email.service_provider }
  let(:service_provider_email_list) { service_provider_email.service_provider_email_list   }

  before :all do
    Resque.inline = true
  end

  describe 'send one marketing email and unsubscribe' do
    before :each do
      reset_email
      PromotionActions.perform :too_low_profile_score, service_provider.id
    end

    it "should have unsubscribe link" do
      last_email.body.should have_content("?????????? ?? ????????")
    end

    it "should have correct city in link" do
      last_email.body.find(:xpath, "//a[@id=\"unsubscribe_link\"][@href=\"http://#{service_provider.city.name}.#{service_provider.country.domain}/#{service_provider.code}?uncheck=marketing]")
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

最后一个例子失败 如何从电子邮件中查询html?

cut*_*ion 8

Capybara.string(last_email.body).find(...)
Run Code Online (Sandbox Code Playgroud)

  • 小修正:`Capybara.string(last_email.body.encoded).find(...)` (3认同)