Module: Ruhl::Rspec::Rails

Defined in:
lib/ruhl/rspec/rails.rb

Class Method Summary collapse

Class Method Details

.included(parent) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruhl/rspec/rails.rb', line 6

def self.included(parent)

  ruby = "    before do\n      f = \"\#{caller[0].split(':').first}\"\n      f = f.sub(\"\\.\\/spec\",\"\#{::Rails.root}\\/app\").sub('_spec.rb','')\n      @view_nodes = Nokogiri::HTML.fragment(File.read(f))\n    end\n\n    def ruhl_view\n      @view_nodes\n    end\n\n    def data_ruhl(path) \n      tag  = ruhl_view.css(path).first\n      unless tag\n        raise Spec::Matchers::MatcherError.new(\"CSS selector: \"+ path + \" not found\")\n      end\n      tag.attribute('data-ruhl').to_s\n    end\n  RUBY\n\n  parent.class_eval ruby\nend\n"