<commit_before>require 'spec_helper'

describe InvisibleCaptcha::ViewHelpers, type: :helper do
  def helper_output(honeypot = nil, scope = nil)
    honeypot ||= InvisibleCaptcha.get_honeypot
    input_id   = build_label_name(honeypot, scope)
    input_name = build_text_field_name(honeypot, scope)
    html_id    = generate_html_id(honeypot, scope)

    %{
      <div id="#{html_id}">
        <style media="screen" scoped="scoped" type="text/css">#{InvisibleCaptcha.visual_honeypots ? '' : "##{html_id} { display:none; }"}</style>
        <label for="#{input_id}">#{InvisibleCaptcha.sentence_for_humans}</label>
        <input id="#{input_id}" name="#{input_name}" type="text" />
      </div>
    }.gsub(/\s+/, ' ').strip.gsub('> <', '><')
  end

  before do
    allow(Time).to receive(:now).and_return(Time.parse('Feb 19 1986'))
    InvisibleCaptcha.visual_honeypots = false
  end

  it 'view helper with no arguments' do
    InvisibleCaptcha.honeypots = [:foo_id]
    expect(invisible_captcha).to eq(helper_output)
  end

  it 'view helper with specific honeypot' do
    expect(invisible_captcha(:subtitle)).to eq(helper_output(:subtitle))
  end<commit_msg>fix specs: seems in Rails 4.2 html attributes are not sorted before render<commit_after>require 'spec_helper'

describe InvisibleCaptcha::ViewHelpers, type: :helper do
  def helper_output(honeypot = nil, scope = nil)
    honeypot ||= InvisibleCaptcha.get_honeypot
    input_id   = build_label_name(honeypot, scope)
    input_name = build_text_field_name(honeypot, scope)
    html_id    = generate_html_id(honeypot, scope)

    %{
      <div id="#{html_id}">
        <style type="text/css" media="screen" scoped="scoped">#{InvisibleCaptcha.visual_honeypots ? '' : "##{html_id} { display:none; }"}</style>
        <label for="#{input_id}">#{InvisibleCaptcha.sentence_for_humans}</label>
        <input type="text" name="#{input_name}" id="#{input_id}" />
      </div>
    }.gsub(/\s+/, ' ').strip.gsub('> <', '><')
  end

  before do
    allow(Time).to receive(:now).and_return(Time.parse('Feb 19 1986'))
    InvisibleCaptcha.visual_honeypots = false
  end

  it 'view helper with no arguments' do
    InvisibleCaptcha.honeypots = [:foo_id]
    expect(invisible_captcha).to eq(helper_output)
  end

  it 'view helper with specific honeypot' do
    expect(invisible_captcha(:subtitle)).to eq(helper_output(:subtitle))
  end
{'fraction_non_alphanumeric': 0.14796132828919714, 'fraction_numerical': 0.0058848255569567045, 'mean_word_length': 4.336322869955157, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3353257', 'n_tokens_mistral': 880, 'n_tokens_neox': 831, 'n_words': 157}