Project

lazy-check

0.0
No release in over a year
This gem is a lazy but serious way of testing that a website is valid in terms of its pages and content.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

Lazy::Check

This gem allows you to lazily test a website.

Installation

Add this line to your application's Gemfile:

gem 'lazy-check'
require 'lazy/check'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install lazy-check

Usage

For a simple test (without a recipe)

If you only have XML-like code to test, you can use the Lazy::Checker#check method.

gem 'lazy-check'
require 'lazy/check'

code = "<root><div class="contains">some text</div></root>"
check = {tag: 'div.contains', text: "some text"}
Lazy::Checker.check(code, check)
# => Output:
#       -------------------------------------
#       Success 1 Failures 0 Duration ...

You can also obtain the results in method return (this is a Lazy::Checker::Reporter).

Lazy::Checker.check(code, check, **{return_result: true})
# => Reporter

Note that in this case, nothing is written in the console.

For a test with a recipe

A "recipe" is a YAML file that defines the url of a web page, and the checks to be performed on it. See below.

require "lazy/check"

checker = Lazy::Checker.new("path/to/recipe.yaml")
checker.check
# => Produces the result

If the recipe is located where the terminal is, simply do:

require "lazy/check"

Lazy::Checker.new.check

The recipe (recipe.yaml) defines the checks to be performed.

---
name: "Name for this recipe"
base: https://www.my.domain.net
tests:
  - name: "My first test"
    url: "" # so the base
    checks:
      - name: "Existence of DIV#content with text"
        tag: 'div#content'
        empty: false
      - name: "Existence of SPAN#range without text"
        tag: 'span#range'
        empty: true
  
      - name: "A redirection"
        url: "redirection.html"
        redirect_to: "https://new.url.net"

      - name: "A wrong page"
        url: "page_unfound.html"
        response: 404

Check Properties

The above "checks" can define the following properties:

tag:                  [String] The selector
count:             [Integer] Expected number of elements
empty:            [Bool] If true, must be empty, if false, must be non-empty
direct_child:   [Bool] If true, must be a direct child
text:                 [String] The text that must be contained
contains:       [String|Array] What the page should contain
min_length: 		[Integer] Minimum content length (text only)
max_length: 		[Integer] Maximum content length (text only)

Examples

Simply check that a page responds correctly:

# recipe.yaml
---
name: "Page exists"
base: 'https://mywebsite.net'
tests: 
	- name: "The index.html page exists and responds correctly"
		url:  'index.html'
		response: 200

Check that a page contains the basic elements.

# recipe.yaml
---
name: "Simple check on the existence of basic elements"
base: 'https://mywebsite.net'
tests: 
	- name: "The index.html page contains the basic elements"
		url:  'index.html'
		checks:
			- tag: 'header'
			- tag: 'section#body'
			- tag: 'footer'

Tests

Run the tests:

rake test

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/PhilippePerret/lazy-check.