Socket
Book a DemoInstallSign in
Socket

rspec-varys

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rspec-varys

0.2.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

Gem Version Build Status Code Climate

Rspec::Varys

Generate RSpec specs from intelligence gathered from doubles and spies. This is an experiment to see if a top-down TDD work-flow can be improved by partially automating the creation of lower level specs.

When you define a test-double in your spec:

describe ExampleClass, "#max_margin_for" do
  it "returns the maximum margin for the supplied text" do
    allow(subject).to receive(:margin_for).and_return(2, 4)
    expect(subject.max_margin_for("  unindent line\n    indented line\n")).to eq(4)
  end
end

And your code calls it:

class ExampleClass
  def max_margin_for(text)
    text.split("\n").map {|line| margin_for(line)}.max
  end
end

Varys will generate the corresponding specs so you can verify the validity of your test-doubles:

# Generated by Varys:

describe ExampleClass, "#margin_for" do
  it "returns something" do
    confirm(subject).can receive(:margin_for).with("  unindent line").and_return(2)
    skip "remove this line once implemented"
    expect(subject.margin_for("  unindent line")).to eq(2)
  end
end

describe ExampleClass, "#margin_for" do
  it "returns something" do
    confirm(subject).can receive(:margin_for).with("    indented line").and_return(4)
    skip "remove this line once implemented"
    expect(subject.margin_for("    indented line")).to eq(4)
  end
end

Limitations

Varys is very early release software and it has many limitations. If you find one, please check the Github issues and add it if it's not already listed.

Installation

Add this line to your application's Gemfile:

gem 'rspec-varys'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-varys

Configuration

Add these lines to your spec/spec_helper.rb:

require "rspec/varys"
require "rspec/varys/rspec_generator"

RSpec.configure do |config|
  config.include RSpec::Varys::DSL

  config.before(:suite) do
    RSpec::Varys.reset
  end

  config.after(:suite) do
    # Required: create varys.yml
    RSpec::Varys.print_report

    # Optional: create generated_specs.yml from varys.yml
    RSpec::Varys::RSpecGenerator.run
  end
end

Usage

See the Cucumber features for examples of intended usage or watch this screencast for a simple tutorial.

Contributing

  • Fork it ( https://github.com/ritchiey/rspec-varys/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 11 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.