如何在Cucumber中测试mailto链接?

时间:2012-05-24 15:25:08

标签: html ruby-on-rails cucumber mailto

我有这样的链接:

  

< a href =“mailto:<%= @email%>?subject =回答投诉& body =<%= @salutation%>,”>答案< / A>

如何使用Cucumber / Capybara进行测试?我的意思不仅仅是

  

我应该看到“答案”

4 个答案:

答案 0 :(得分:1)

听起来您担心@email链接中的@salutationmailto:值是正确的。

你可以做这样的事情

page.should have_xpath("//a[contains(@href,email)]"))

答案 1 :(得分:0)

我最终选择了Cucumber:

Then /^I should have a mailto link with:$/ do |table| 
  mailto_link = '//a[@href="mailto:' + table.rows_hash['recipient'] + '?subject=' + table.rows_hash['subject'] + '&body=' + table.rows_hash['body'] + ' "]'
  page.should have_xpath(mailto_link)
end

答案 2 :(得分:0)

Piotr Brudny添加了URL编码并包含参数顺序无关紧要(我从那里删除了身体,但如果你需要它,你可能会想出来。

Then(/^I should have a mailto link with:$/) do |table|
  mailto_link = ("//a[contains(@href, \"mailto:#{table.rows_hash['recipient']}\")"\
  " and contains(@href, \""+ {
    subject: table.rows_hash['subject']
  }.to_query + '")]').gsub('+', '%20')
  page.should(have_xpath(mailto_link))
end

答案 3 :(得分:0)

与接受的答案类似,但略有更新的例子。你可以这样说:

select 
    conname as constraint_name,
    conrelid::regclass as table_name,
    get_col_names(conrelid, conkey) as column_names,
    confrelid::regclass as foreign_table_name,
    get_col_names(confrelid, confkey) as foreing_column_names
from pg_constraint
where contype ='f'
and conrelid = 'comment'::regclass;

  constraint_name  | table_name | column_names | foreign_table_name | foreing_column_names 
-------------------+------------+--------------+--------------------+----------------------
 comment_name_fkey | comment    | name, owner  | cat                | name, owner
(1 row)