Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 16 commits
  • 10 files changed
  • 0 comments
  • 2 contributors
3  .travis.yml
... ... @@ -1,3 +1,6 @@
  1 +before_script:
  2 + - "export DISPLAY=:99.0"
  3 + - "sh -e /etc/init.d/xvfb start"
1 4 rvm:
2 5 - 1.8.7
3 6 - 1.9.2
5 CHANGELOG.md
Source Rendered
@@ -7,6 +7,11 @@ unreleased(TODO)
7 7 * improve documentation(look at changelog and code!)
8 8 * add :without to have\_tag? like have_tag('div', :without => { :class => 'test' })
9 9
  10 +0.3.4
  11 +-----
  12 +
  13 +* capybara support
  14 +
10 15 0.2.4
11 16 -----
12 17
6 README.md
Source Rendered
@@ -89,6 +89,12 @@ end
89 89 '<p class="qwe rty" id="qwerty">Paragraph</p>'.should have_tag('p', :with => { :class => ['qwe', 'rty'] })
90 90 ```
91 91
  92 +usage with capybara and cucumber:
  93 +
  94 + page.should have_tag( ... )
  95 +
  96 +where `page` is an instance of Capybara::Session
  97 +
92 98 Also included special matchers for form inputs:
93 99 -----------------------------------------------
94 100
8 Rakefile
... ... @@ -1,10 +1,11 @@
1 1 require 'bundler'
2 2 require 'rspec/core/rake_task'
  3 +require 'cucumber/rake/task'
3 4 Bundler::GemHelper.install_tasks
4 5
5 6 gemspec = eval(File.read(Dir["*.gemspec"].first))
6 7
7   -task :default => :spec
  8 +task :default => [:spec, :cucumber]
8 9
9 10 RSpec::Core::RakeTask.new(:spec) do |t|
10 11 t.rspec_opts='--tag ~wip'
@@ -25,3 +26,8 @@ namespace :spec do
25 26 t.rspec_opts=['-r simplecov']
26 27 end
27 28 end
  29 +
  30 +Cucumber::Rake::Task.new(:cucumber) do |t|
  31 + t.fork = true
  32 + t.profile = 'default'
  33 +end
1  cucumber.yml
... ... @@ -0,0 +1 @@
  1 +default: --strict features
23 features/ajax_generated_content.feature
... ... @@ -0,0 +1,23 @@
  1 +Feature: Javascript generated content
  2 +
  3 + Scenario: Test with js
  4 + Given I have following template:
  5 + """
  6 + <!DOCTYPE html>
  7 + <html>
  8 + <head>
  9 + <meta charset="utf-8">
  10 + <title>HTML5 Template</title>
  11 + </head>
  12 + <body>
  13 + <h1>Hello World!</h1>
  14 +
  15 + <script type="text/javascript">
  16 + document.write('<p>Hello Another World!</p>');
  17 + </script>
  18 + </body>
  19 + </html>
  20 + """
  21 + When I open this template in browser
  22 + Then I should be able to match static content
  23 + And I should be able to match javascript generated content
27 features/step_definitions/steps.rb
... ... @@ -0,0 +1,27 @@
  1 +Given /^I have following template:$/ do |string|
  2 + File.open($INDEX_HTML,'w+') do |file|
  3 + file.write(string)
  4 + end
  5 +end
  6 +
  7 +When /^I open this template in browser$/ do
  8 + visit('/index.html')
  9 +end
  10 +
  11 +Then /^I should be able to match static content$/ do
  12 + # capybara:
  13 + page.should have_content('Hello World!')
  14 + page.should have_css('h1')
  15 +
  16 + # rspec2 matchers:
  17 + page.should have_tag('h1', :text => 'Hello World!')
  18 +end
  19 +
  20 +Then /^I should be able to match javascript generated content$/ do
  21 + # capybara:
  22 + page.should have_content('Hello Another World!')
  23 + page.should have_css('p')
  24 +
  25 + # rspec2 matchers:
  26 + page.should have_tag('p', :text => 'Hello Another World!')
  27 +end
17 features/support/env.rb
... ... @@ -0,0 +1,17 @@
  1 +require 'sinatra/base'
  2 +require 'capybara/cucumber'
  3 +require 'rspec-html-matchers'
  4 +
  5 +$ASSETS_DIR = File.join(Dir.pwd,'assets')
  6 +$INDEX_HTML = File.join($ASSETS_DIR,'index.html')
  7 +
  8 +class SimpleApp < Sinatra::Base
  9 + set :public_folder, $ASSETS_DIR
  10 +end
  11 +
  12 +Capybara.default_driver = :selenium
  13 +Capybara.app = SimpleApp
  14 +
  15 +After do
  16 + FileUtils.rm $INDEX_HTML
  17 +end
2  lib/rspec-html-matchers.rb
@@ -56,6 +56,8 @@ def initialize tag, options={}, &block
56 56 def matches? document, &block
57 57 @block = block if block
58 58
  59 + document = document.html if defined?(Capybara) && document.is_a?(Capybara::Session)
  60 +
59 61 case document
60 62 when String
61 63 @parent_scope = @current_scope = Nokogiri::HTML(document).css(@tag)
5 rspec-html-matchers.gemspec
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3 3
4 4 Gem::Specification.new do |s|
5 5 s.name = "rspec-html-matchers"
6   - s.version = '0.2.4'
  6 + s.version = '0.3.4'
7 7 s.platform = Gem::Platform::RUBY
8 8 s.authors = ["kucaahbe"]
9 9 s.email = ["kucaahbe@ukr.net"]
@@ -24,5 +24,8 @@ DESC
24 24 s.add_dependency 'nokogiri', '>= 1.4.4'
25 25
26 26 s.add_development_dependency 'simplecov'
  27 + s.add_development_dependency 'cucumber'
  28 + s.add_development_dependency 'capybara'
  29 + s.add_development_dependency 'sinatra'
27 30 s.add_development_dependency 'rake'
28 31 end

No commit comments for this range

Something went wrong with that request. Please try again.