Module: Ruhl::Rspec::Sinatra

Defined in:
lib/ruhl/rspec/sinatra.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
30
31
32
# File 'lib/ruhl/rspec/sinatra.rb', line 6

def self.included(parent)

  ruby = <<-RUBY
    before do
      origin = "#{caller[0].split(':').first}"

      f = origin.sub(/\\/spec\\//,'/app/')
      f = f.sub('_spec.rb','')

      @view_nodes = Nokogiri::HTML.fragment(File.read(f))
    end

    def ruhl_view
      @view_nodes
    end

    def data_ruhl(path) 
      tag  = ruhl_view.css(path).first
      unless tag
        raise Spec::Matchers::MatcherError.new("CSS selector: "+ path + " not found")
      end
      tag.attribute('data-ruhl').to_s
    end
  RUBY

  parent.class_eval ruby
end