├── Gemfile ├── solver.rb ├── .github └── workflows │ └── linters.yml ├── Gemfile.lock ├── LICENSE ├── .rubocop.yml ├── spec └── solver_spec.rb └── README.md /Gemfile: -------------------------------------------------------------------------------- 1 | gem 'rubocop', '>= 1.0', '< 2.0' 2 | -------------------------------------------------------------------------------- /solver.rb: -------------------------------------------------------------------------------- 1 | class Solver 2 | def self.factorial(number) 3 | raise ArgumentError, 'Only accepts 0 and positive integers' if number.negative? 4 | 5 | (1..number).reduce(1, :*) 6 | end 7 | 8 | def self.reverse(word) 9 | word.reverse 10 | end 11 | 12 | def self.fizzbuzz(number) 13 | return 'fizzbuzz' if (number % 3).zero? && (number % 5).zero? 14 | return 'fizz' if (number % 3).zero? 15 | return 'buzz' if (number % 5).zero? 16 | 17 | number.to_s 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /.github/workflows/linters.yml: -------------------------------------------------------------------------------- 1 | name: Linters 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | rubocop: 7 | name: Rubocop 8 | runs-on: ubuntu-22.04 9 | 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-ruby@v1 13 | with: 14 | ruby-version: ">=3.1.x" 15 | - name: Setup Rubocop 16 | run: | 17 | gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/ 18 | [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml 19 | - name: Rubocop Report 20 | run: rubocop --color -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | specs: 3 | ast (2.4.2) 4 | base64 (0.1.1) 5 | json (2.5.1) 6 | language_server-protocol (3.17.0.3) 7 | parallel (1.23.0) 8 | parser (3.2.2.3) 9 | ast (~> 2.4.1) 10 | racc 11 | racc (1.7.1) 12 | rainbow (3.1.1) 13 | regexp_parser (2.8.1) 14 | rexml (3.2.5) 15 | rubocop (1.56.1) 16 | base64 (~> 0.1.1) 17 | json (~> 2.3) 18 | language_server-protocol (>= 3.17.0) 19 | parallel (~> 1.10) 20 | parser (>= 3.2.2.3) 21 | rainbow (>= 2.2.2, < 4.0) 22 | regexp_parser (>= 1.8, < 3.0) 23 | rexml (>= 3.2.5, < 4.0) 24 | rubocop-ast (>= 1.28.1, < 2.0) 25 | ruby-progressbar (~> 1.7) 26 | unicode-display_width (>= 2.4.0, < 3.0) 27 | rubocop-ast (1.29.0) 28 | parser (>= 3.2.1.0) 29 | ruby-progressbar (1.13.0) 30 | unicode-display_width (2.4.2) 31 | 32 | PLATFORMS 33 | x86_64-linux 34 | 35 | DEPENDENCIES 36 | rubocop (>= 1.0, < 2.0) 37 | 38 | BUNDLED WITH 39 | 2.4.19 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Nitcelis Bravo and Ahmed Eid. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | NewCops: enable 3 | Exclude: 4 | - "Guardfile" 5 | - "Rakefile" 6 | - "node_modules/**/*" 7 | 8 | DisplayCopNames: true 9 | 10 | Layout/LineLength: 11 | Max: 120 12 | Metrics/MethodLength: 13 | Max: 20 14 | Metrics/AbcSize: 15 | Max: 50 16 | Metrics/ClassLength: 17 | Max: 150 18 | Metrics/BlockLength: 19 | IgnoredMethods: ['describe'] 20 | Max: 30 21 | 22 | 23 | Style/Documentation: 24 | Enabled: false 25 | Style/ClassAndModuleChildren: 26 | Enabled: false 27 | Style/EachForSimpleLoop: 28 | Enabled: false 29 | Style/AndOr: 30 | Enabled: false 31 | Style/DefWithParentheses: 32 | Enabled: false 33 | Style/FrozenStringLiteralComment: 34 | EnforcedStyle: never 35 | 36 | Layout/HashAlignment: 37 | EnforcedColonStyle: key 38 | Layout/ExtraSpacing: 39 | AllowForAlignment: false 40 | Layout/MultilineMethodCallIndentation: 41 | Enabled: true 42 | EnforcedStyle: indented 43 | Lint/RaiseException: 44 | Enabled: false 45 | Lint/StructNewOverride: 46 | Enabled: false 47 | Style/HashEachMethods: 48 | Enabled: false 49 | Style/HashTransformKeys: 50 | Enabled: false 51 | Style/HashTransformValues: 52 | Enabled: false -------------------------------------------------------------------------------- /spec/solver_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../solver' 2 | 3 | describe Solver do 4 | describe '#factorial' do 5 | it 'returns 1 for factorial of 0' do 6 | expect(Solver.factorial(0)).to eq(1) 7 | end 8 | 9 | it 'returns the factorial of a positive number' do 10 | expect(Solver.factorial(5)).to eq(120) 11 | end 12 | 13 | it 'raises an exception for a negative number' do 14 | expect { Solver.factorial(-1) }.to raise_error(ArgumentError) 15 | end 16 | end 17 | 18 | describe '#reverse' do 19 | it 'returns the reversed word' do 20 | expect(Solver.reverse('hello')).to eq('olleh') 21 | end 22 | end 23 | 24 | describe '#fizzbuzz' do 25 | it 'returns "fizz" when the number is divisible by 3' do 26 | expect(Solver.fizzbuzz(9)).to eq('fizz') 27 | end 28 | 29 | it 'returns "buzz" when the number is divisible by 5' do 30 | expect(Solver.fizzbuzz(10)).to eq('buzz') 31 | end 32 | 33 | it 'returns "fizzbuzz" when the number is divisible by 3 and 5' do 34 | expect(Solver.fizzbuzz(15)).to eq('fizzbuzz') 35 | end 36 | 37 | it 'returns the number as a string for any other case' do 38 | expect(Solver.fizzbuzz(7)).to eq('7') 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |

TDD Project | Ruby

5 |
6 | 7 | 8 | 9 | # 📗 Table of Contents 10 | 11 | - [📗 Table of Contents](#-table-of-contents) 12 | - [TDD Project ](#tdd-project-) 13 | - [🛠 Built With ](#-built-with-) 14 | - [Tech Stack ](#tech-stack-) 15 | - [Key Features ](#key-features-) 16 | - [💻 Getting Started ](#-getting-started-) 17 | - [Prerequisites](#prerequisites) 18 | - [Setup](#setup) 19 | - [Install](#install) 20 | - [Run tests](#run-tests) 21 | - [👥 Authors ](#-authors-) 22 | - [🔭 Future Features ](#-future-features-) 23 | - [🤝 Contributing ](#-contributing-) 24 | - [⭐️ Show your support ](#️-show-your-support-) 25 | - [🙏 Acknowledgments ](#-acknowledgments-) 26 | - [📝 License ](#-license-) 27 | 28 | --- 29 | 30 | 31 | 32 | # TDD Project 33 | 34 | **"TDD Project"** consists of creating test cases using the Rspec gem and applying the TDD methodology to a series of methods within a class. The purpose of the project is to practice testing following the best practices and applying a more optimal approach (TDD), which allows obtaining a more stable, clean and maintainable code. 35 | 36 | --- 37 | 38 | ## 🛠 Built With 39 | 40 | ### Tech Stack 41 | 42 |
43 | Ruby 44 | 47 | Rspec gem 48 | 51 |
52 | 53 | --- 54 | 55 | 56 | 57 | ### Key Features 58 | 59 | 68 | 69 |

(back to top)

70 | 71 | --- 72 | 73 | 74 | 75 | ## 💻 Getting Started 76 | 77 | To get a local copy up and running, follow these steps. 78 | 79 | ### Prerequisites 80 | 81 | In order to run this project you need: 82 | 83 | 86 | 87 | 90 | 91 | ### Setup 92 | 93 | Clone this repository to your desired folder by using this 👇️ command : 94 | 95 | ``` 96 | git clone https://github.com/ahmedeid6842/TDD.git 97 | ``` 98 | 99 | ### Install 100 | 101 | Go to the project directory: 102 | 103 | ``` 104 | cd TDD 105 | ``` 106 | 107 | Before to run the program, verify that you have Ruby installed on your OS running the following command: 108 | 109 | ``` 110 | ruby -v 111 | ``` 112 | 113 | It should show you the version of ruby ​​installed. If this does not happen and only an error message is displayed, then you should either verify your installation or install Ruby from scratch. 114 | 115 | [Download and Install Ruby](https://www.ruby-lang.org/en/downloads/) 116 | 117 | ### Run tests 118 | 119 | Run the following command inside the project folder: 120 | 121 | ``` 122 | rspec spec 123 | ``` 124 | 125 | This should display: 126 | 127 | ``` 128 | 8 examples, 0 failures 129 | ``` 130 | 131 | This means that all 8 designed test cases have passed successfully. 132 | 133 |

(back to top)

134 | 135 | --- 136 | 137 | 138 | 139 | ## 👥 Authors 140 | 141 | 👤 **Nitcelis Bravo** 142 | 143 | - GitHub: [Nitcelis Bravo](https://github.com/NitBravoA92) 144 | - Twitter: [@softwareDevOne](https://twitter.com/softwareDevOne) 145 | - LinkedIn: [Nitcelis Bravo Alcala](https://www.linkedin.com/in/nitcelis-bravo-alcala-b65340158) 146 | 147 | 👤 **Ahmed Eid** 148 | 149 | - GitHub: [Ahmed Eid](https://github.com/ahmedeid6842) 150 | - Twitter: [@ahmedeid2684](https://twitter.com/ahmedeid2684) 151 | - LinkedIn: [Ahmed Eid](https://www.linkedin.com/in/ameid/) 152 | 153 |

(back to top)

154 | 155 | --- 156 | 157 | 158 | 159 | ## 🔭 Future Features 160 | 161 | Upcoming improvements: 162 | 163 | - [x] Create unit tests following TDD methodology 164 | 165 |

(back to top)

166 | 167 | --- 168 | 169 | 170 | 171 | ## 🤝 Contributing 172 | 173 | Contributions, issues, and feature requests are welcome! 174 | 175 | Feel free to check the [issues page](https://github.com/ahmedeid6842/TDD/issues). 176 | 177 |

(back to top)

178 | 179 | --- 180 | 181 | 182 | 183 | ## ⭐️ Show your support 184 | 185 | If you like this project and know someone who might find it helpful, please share it. 186 | Or give it a **star** ⭐️ if you like this project! 187 | 188 |

(back to top)

189 | 190 | --- 191 | 192 | 193 | 194 | ## 🙏 Acknowledgments 195 | 196 | I thank Microverse for this fantastic opportunity, and the code reviewers for their advice and time. 197 | 198 |

(back to top)

199 | 200 | --- 201 | 202 | 203 | 204 | ## 📝 License 205 | 206 | This project is [MIT](./LICENSE) licensed. 207 | 208 |

(back to top)

209 | 210 | --- 211 | --------------------------------------------------------------------------------