Code Monkey home page Code Monkey logo

ruby-yslow's Introduction

YSlow on Ruby

Build Status ย  Gem Version

Ruby wrapper for YSlow via PhantomJS.

Install

gem install yslow

# via bundler
bundle init
echo "gem 'yslow'" >> Gemfile
bundle install

Example Usage

:::ruby
#!/usr/bin/ruby
require "yslow"

YSlow.path
# => /path/to/yslow.js
#
# Accepts custom path
# YSlow.path "/path/to/yslow.js"

YSlow.phantomjs
# => /path/to/phantomjs
#
# Accepts custom path
# YSlow.phantomjs "/path/to/phantomjs"

result = YSlow.run "http://www.example.com"
      # , [ .. other yslow args .. ]

result
# => YSlow::Result

result.result
# yslow result hash

# YSlow::Result#result  :: raw result hash
# YSlow::Result#status  :: exit status
# YSlow::Result#stdout  :: raw stdout string
# YSlow::Result#stderr  :: raw stderr string
# YSlow::Result#to_i    :: exit status
# YSlow::Result#to_s    :: stdout if pass, else stderr
# YSlow::Result#to_json :: stdout as json if passed, else result as json
# YSlow::Result#to_h    :: parsed stdout hash if passed, else result as hash

See examples/basic.rb for a runnable example.

Example Usage: Test

:::ruby
require "minitest/autorun"
require "yslow"

class TestExampleDotCom < Minitest::Unit::TestCase
  def setup
    @result ||= YSlow.run "http://www.example.com"
  end

  def test_yslow_grade
    assert (95..100).include?(@result.to_h["o"]),
      "expected grade to be between 95 and 100"
            # grade was 98 when this was created
  end

  def test_requests
    assert (0..4).include?(@result.to_h["r"]),
      "expected requests to be between 0 and 4"
            # requests was 2 when this was created
  end

  def test_load_time
    assert (0..200).include?(@result.to_h["lt"]),
      "expected load time to be between 0 and 200"
            # load time was 67 when this was created
  end

  def test_size
    assert (2000..3000).include?(@result.to_h["w"]),
      "expected page size to be between 2000 and 3000"
            # load time was 2540 when this was created
  end
end

See examples/minitest.rb for a runnable example.

Development

git clone https://github.com/jmervine/ruby-yslow.git
cd ruby-yslow
bundle install --path vendor/bundle
bundle exec rake test

ruby-yslow's People

Contributors

jmervine avatar hlascelles avatar

Stargazers

Chris Hough avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

pureoxygen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.