Giter Site home page Giter Site logo

rspec-template's Introduction

rspec-template

Installation

This project hasn't been submitted to rubygems, so:

$ git clone https://github.com/wils3005/rspec-template
$ cd rspec-template
$ rake install

Usage

# use it interactively through irb or pry
# e.g.
$ irb
irb(main):001:0> require 'rspec/template'
=> true
irb(main):002:0> File.write('my_spec.rb', RSpec::Template.new(Object))
=> 128

# a rails generator is also provided
# bundle exec rails generate rspec:template [CLASS_NAME]
# e.g.
$ bundle exec rails generate rspec:template User > user_spec.rb
# frozen_string_literal: true

RSpec.describe User do
  subject :described_instance do
    described_class.new(attributes, options)
  end

  let :attributes do
    double('attributes')
  end

  let :options do
    double('options')
  end

  describe '.my_class_method' do
    subject :described_method do
      described_class.my_class_method(foo: foo, bar: bar)
    end

    let :foo do
      double('foo')
    end

    let :bar do
      double('bar')
    end

    context 'when called' do
      it 'does not raise an error' do
        expect { described_method }.not_to(raise_error)
      end
    end
  end

  describe '#authenticate' do
    subject :described_method do
      described_instance.authenticate(email, password)
    end

    let :email do
      double('email')
    end

    let :password do
      double('password')
    end

    context 'when called' do
      it 'does not raise an error' do
        expect { described_method }.not_to(raise_error)
      end
    end
  end

  describe '#admin?' do
    subject :described_method do
      described_instance.admin?
    end

    context 'when called' do
      it 'does not raise an error' do
        expect { described_method }.not_to(raise_error)
      end
    end
  end
end

License

Copyright (c) 2020 Jack Wilson. See LICENSE for further details.

rspec-template's People

Contributors

wils3005 avatar

Watchers

 avatar  avatar

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.