Code Monkey home page Code Monkey logo

boris-bikes's Introduction

Boris Bikes

Module: Ruby, Rspec, TDD, Planning, and Collaborating

User Story | DockingStation Rspec File | Bike Rspec File | DockingStation Ruby Code | Bike Ruby Code

Due to the climate crisis, more roads are being closed off. Scientists on climate change suggested in order to save our future we must reduce our carbon footprint โ€” and cycling for transportation is one of them. The government announced investing a significant amount of money towards 'Boris Bikes' so that everyone can do their part for the planet, whilst also, keeping fit. Lucky you, you're offered the job to build a program that will run all the Docking Stations, simulate all the bikes, and emulate all the infrastructure (vans, repair staff, and logistics) required to make their ambitious plans a reality.

'User Stories' are short, simple descriptions of a feature told from the perspective of the person who desires the new capability,usually a user or a client of the system.

" As a person, So that I can use a bike, I'd like a docking station to release a bike.

As a person, So that I can use a good bike, I'd like to see if a bike is working

As a person, So that I can use a bike, I'd like to get a bike from a docking station.

As a person, So that I can use a good bike, I'd like to see if a bike is working

As a member of the public So I can return bikes I've hired I want to dock my bike at the docking station

As a member of the public So I can decide whether to use the docking station I want to see a bike that has been docked

As a member of the public, So that I am not confused and charged unnecessarily, I'd like docking stations not to release bikes when there are none available.

As a maintainer of the system, So that I can control the distribution of bikes, I'd like docking stations not to accept more bikes than their capacity.

As a system maintainer, So that I can plan the distribution of bikes, I want a docking station to have a default capacity of 20 bikes.

As a system maintainer, So that busy areas can be served more effectively, I want to be able to specify a larger capacity when necessary.

As a member of the public, So that I reduce the chance of getting a broken bike in future, I'd like to report a bike as broken when I return it.

As a maintainer of the system, So that I can manage broken bikes and not disappoint users, I'd like docking stations not to release broken bikes.

As a maintainer of the system, So that I can manage broken bikes and not disappoint users, I'd like docking stations to accept returning bikes (broken or not). "

"require "docking_station" describe 'DockingStation' do"

Create bike double and allow it to access variable "working"

let(:bike) { double :bike, :working= => true, working?: false}

TEST: Release a bike

it { is_expected.to respond_to :release_bike }

TEST: Release only a working bike

it 'releases a bike if working' do allow(bike).to receive(:working?).and_return(true) subject.dock_bike(bike) expect(subject.release_bike).to be_working end

TEST: Check method dock_bike responds to 1 argument

it { is_expected.to respond_to(:dock_bike).with(1).argument }

TEST: Dock a bike successfully

it 'docks something' do allow(bike).to receive(:working?) expect(subject.dock_bike(bike)).to eq [bike] end

TEST: Fill docking station up and check for full error

it "gives an error when docking station is full" do DockingStation::DEFAULT_CAPACITY.times { subject.dock_bike(bike) } expect{subject.dock_bike(bike)}.to raise_error 'Full dock' end

TEST: Dock a bike then release the same bike

it 'releases a bike' do allow(bike).to receive(:working?).and_return(true) subject.dock_bike(bike) expect(subject.release_bike).to eq bike end

TEST: Test for error if docking station is empty

it 'raises an error if dock empty' do expect {subject.release_bike}.to raise_error 'Empty dock' end

Test different size docking stations

it 'Allow user to set capacity of docking station' do

Create a new station with 50 bikes and test

num = 50 station = DockingStation.new(num) expect(station.capacity).to eq num

Create a default station using the DEFAULT_CAPACITY constant

station = DockingStation.new expect(station.capacity).to eq DockingStation::DEFAULT_CAPACITY end

"ruby require "bike" describe 'bike' do"

TEST: check to see if we can respond to method working?

it {is_expected.to respond_to :working?} end "

"

require_relative 'bike'

class DockingStation

DEFAULT_CAPACITY = 20

attr_reader :capacity

def initialize(capacity=DEFAULT_CAPACITY) @docked = [] @capacity = capacity end

def release_bike raise "Empty dock" if empty? docked.each_with_index {|bike,index| docked.delete_at(index) ; return bike if bike.working? } raise "All bikes broken!" end

def dock_bike(bike, working = true) raise "Full dock" if full? bike.working = false if !working docked << bike end

private

attr_reader :docked def full? docked.count >= capacity end

def empty? docked.empty? end

"ruby class "Bike" 'bike'" end

attr_accessor :working

def initialize(work=true) @working = "work" end

"ruby def "working?" 'work'" end

boris-bikes's People

Contributors

ghostglass avatar notatiyyah avatar

Stargazers

 avatar

Watchers

 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.