File: shared_examples.rb

package info (click to toggle)
ruby-cocoon 1.2.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: javascript: 7,776; ruby: 805; makefile: 5
file content (73 lines) | stat: -rw-r--r-- 2,245 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- encoding : utf-8 -*-
shared_examples_for "a correctly rendered add link" do |options|
  context "the rendered link" do
    before do
      default_options = {
          href: '#',
          class: 'add_fields',
          template: "form<tag>",
          association: 'comment',
          associations: 'comments',
          text: 'add something',
          extra_attributes: {}
      }
      @options = default_options.merge options

      doc = Nokogiri::HTML(@html)
      @link = doc.at('a')
    end
    it 'has a correct href' do
      expect(@link.attribute('href').value).to eq(@options[:href])
    end
    it 'has a correct class' do
      expect(@link.attribute('class').value).to eq(@options[:class])
    end
    it 'has a correct template' do
      expect(@link.attribute('data-association-insertion-template').value).to eq(@options[:template])
    end
    it 'has a correct associations' do
      expect(@link.attribute('data-association').value).to eq(@options[:association])
      expect(@link.attribute('data-associations').value).to eq(@options[:associations])
    end
    it 'has the correct text' do
      expect(@link.text).to eq(@options[:text])
    end
    it 'sets extra attributes correctly' do
      @options[:extra_attributes].each do |key, value|
        expect(@link.attribute(key).value).to eq(value)
      end
    end

  end
end

shared_examples_for "a correctly rendered remove link" do |options|
  context "the rendered link" do
    before do
      default_options = {
          href: '#',
          class: 'remove_fields dynamic',
          text: 'remove something',
          extra_attributes: {}
      }
      @options = default_options.merge options

      doc = Nokogiri::HTML(@html)
      @link = doc.at('a')
    end
    it 'has a correct href' do
      expect(@link.attribute('href').value).to eq(@options[:href])
    end
    it 'has a correct class' do
      expect(@link.attribute('class').value).to eq(@options[:class])
    end
    it 'has the correct text' do
      expect(@link.text).to eq(@options[:text])
    end
    it 'sets extra attributes correctly' do
      @options[:extra_attributes].each do |key, value|
        expect(@link.attribute(key).value).to eq(value)
      end
    end
  end
end