GithubHelp home page GithubHelp logo

ar4mro / rspec-examples Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 10 KB

This is a collection of basic rspec examples I used to learn more about this kind of testing. They are well commented and easy to understand.

Ruby 100.00%

rspec-examples's Introduction

What is it?

This is a collection of basic rspec examples from tutorialspoint I used to learn more about this kind of testing, they are enumerated from 0 to 11, being 0 the most basic examples and 11 the last of them. Comments are inside each example and the code is easy to understand.

Each example looks like:

# Let’s say you are building an application for a school and you have a class
# representing a classroom of students and another class for students
class ClassRoom
   def initialize(students)
     @students = students
   end

   def list_student_names
     # By prepending & to a symbol you are creating a lambda function that will
     # call method with a name of that symbol on the object you pass into this
     # function
     @students.map(&:name).join(',')
   end
end

# If we have a “dummy” class that behaves like a Student object then our
# ClassRoom tests will not depend on the Student class. We call this test
# isolation. If our ClassRoom tests don’t rely on any other classes, then when
# a test fails, we can know immediately that there is a bug in our ClassRoom
# class and not some other class
describe ClassRoom do
   it 'the list_student_names method should work correctly' do
     student1 = double('student')
     student2 = double('student')

     allow(student1).to receive(:name) { 'John Smith'}
     allow(student2).to receive(:name) { 'Jill Smith'}

     class_room = ClassRoom.new [student1,student2]
     expect(class_room.list_student_names).to eq('John Smith,Jill Smith')
   end
end

Running Examples

# Running all the examples
$ rspec

# Running an specific example
$ rspec my_example_spec.rb

The implementation of these tests in detail can be found here.


rspec-examples's People

Contributors

ar4mro avatar

Watchers

James Cloos 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.