Ruby TDD Basics with RSpec (Test Driven RSpec, Ep 01)

Sdílet
Vložit
  • čas přidán 12. 06. 2024
  • I walk through the process of creating a Dog class through test-driven development with RSpec and Ruby. The basic gist of TDD is red, green, refactor. This means you start by writing a failing test and then write code in your app to make the test either pass or change its failure. Once the test is green, you revise your code to improve it (called refactoring). Then you write the next failing test and keep on with that cycle.
    It's an effective and fun way to code. It allows for more confidence when making sweeping changes that functionality elsewhere in your code didn't change. It also describes what your code is intended to do, as a form of documentation. Writing tests first also catches bugs earlier in the development process.
    Code from the episode: github.com/brettchalupa/test-...
    Software used:
    - Ruby 2.3.1
    - RSpec 3.5.0
    - Mac OS
    - iTerm 2
    - Vim
    - Tmux
    Feedback on content, text size, talking speed, and quality would be much appreciated.
    Support my screencasts by buying me a coffee: www.buymeacoffee.com/brettcha...
  • Věda a technologie

Komentáře • 51

  • @ES11777
    @ES11777 Před rokem +5

    5 years later your video is still very helpful for beginners in coding! Thank you!

    • @brettcodes
      @brettcodes  Před rokem +1

      Glad to hear it, thanks for watching!

  • @TrustedGG
    @TrustedGG Před 4 měsíci

    First Comment From Me ❤ Wishing you the best sir 🙏🙏

  • @landon.cunningham
    @landon.cunningham Před 3 lety +2

    Really good man - I love the approach of starting simple and building up explaining the purpose of each as you go. Best video I've seen on RSpec.

  • @njaff6104
    @njaff6104 Před rokem +1

    you have really really benefited me with these video. As a gesture of appreciation I just purchased the series which i know is priceless. Thank you!

    • @brettcodes
      @brettcodes  Před rokem

      I am so glad to hear it, and I appreciate your support. Thank you!

  • @varunafernando
    @varunafernando Před 6 lety +2

    Really well explained Monoso. Love your work!

  • @rameshbalakrishnan_meoooow

    wow finally I understood what are all those magical code behinds are for..like subject, described_class etc., easily the best video out there...

  • @livelymissh
    @livelymissh Před 11 měsíci

    Thank you! Really clear explanation and perfect level of detail

  • @cicciopasticcio8469
    @cicciopasticcio8469 Před 4 lety

    Congrats. I have finally understood RSpec!

  • @SXCRD
    @SXCRD Před 6 lety +9

    Is there a part 2?
    The best test video I've seen!
    Would love and appreciate another one ☺

    • @brettcodes
      @brettcodes  Před 6 lety +4

      Thanks for the kind words. There's not a part 2 yet, but I'm planning on returning to the series and creating new videos before the year ends. 😃

    • @SXCRD
      @SXCRD Před 6 lety +1

      Great news! I'll click that bell to get a notification, looking forward to it thanks :D

  • @ashishchougule4790
    @ashishchougule4790 Před 2 lety

    Excellent video!!! I have finally understood RSpec! Thanks a lot Brett!

    • @brettcodes
      @brettcodes  Před 2 lety

      So glad to hear it, thanks for the kind words!

  • @osyopans
    @osyopans Před 3 lety +1

    Amazing work there. Thanks so much.

  • @haroldpepete
    @haroldpepete Před 2 lety

    somebody hate your keyboard sound but i love it, it feel relaxing, i discover your channel one week ago and let me tell you something, you deserve more views than you have right now, i was the typical no testing engineer but i had to learn it and it's not dificult

    • @brettcodes
      @brettcodes  Před 2 lety

      I appreciate your kind words! I hope your journey into testing continues to go well, I personally find it fun and rewarding. It helps me write better code and organize my thoughts. Cheers!

  • @primetimetran
    @primetimetran Před 6 lety +8

    Can't believe you have so few views. Awesome tutorial. Cover a lot of things I use at work every other day =)

  • @herculesledonger2713
    @herculesledonger2713 Před 5 lety +5

    great video, the rspec docs seem to omit how to use context, let, etc.. thanks for demystifying it for us

  • @damndamnd
    @damndamnd Před 11 měsíci

    bonus of keyboard asmr bless mechanical keyboard clacky clack

  • @smn2542
    @smn2542 Před 2 lety

    Best explanation!! Thank you so much

  • @juanhuttemann
    @juanhuttemann Před 6 lety +1

    excellent video!!!

  • @ssergiomaia
    @ssergiomaia Před 7 lety +5

    Awesome!

  • @crazyoptimist4540
    @crazyoptimist4540 Před 3 lety

    Thanks a lot Brad!

  • @eduardoauditore5414
    @eduardoauditore5414 Před 3 lety

    I'm learning Ruby but the sound of the keyboard is asmr for me :D

  • @love_tacos
    @love_tacos Před 3 lety

    Are people watching this really able to follow along from 0:00 without being lost? Needing to create a directory structure with a Gemfile and running 'bundle install' are essential first steps; Perhaps this is more revealing about my knowledge level; however I was directed here via The Odin Project and self-taught learners would need to be comfortable setting up the Gemfile and creating the Gemfile.lock; also, they'd need to run 'rspec dog_spec.rb' instead of 'bundle exec rspec dog_spec.rb'; Perhaps i'm wrong...but the video is full of great tips/tricks/hints

    • @brettcodes
      @brettcodes  Před 3 lety

      I appreciate the feedback, this really helps me out. I'd love to create a prequel-esque video that covers installing RSpec and running tests and other commands. I'll add it to my list of vids!

  • @keith4505
    @keith4505 Před 2 lety

    Thank you for the well explained tutorial! Subbed 😁. Would love to know your vim setup and commands/shortcuts (could be an idea for future videos).
    I like using vim and I’m using the extension on vscode but setting everything up in a meaningful way is quite tedious especially for a new dev like myself.

    • @brettcodes
      @brettcodes  Před 2 lety +1

      Thanks for the sub! I use a customized dotmatrix for my terminal/vim config: github.com/hashrocket/dotmatrix It's got a lot of great plugins and sensible defaults. Love the idea of doing a video on it, thanks for the suggestion! I think what I'll do is fork dotmatrix, commit my changes, and maintain that so it's easy to reference.
      The main command I use when running the tests is \t and \T (leader-t and leader-T). They run the spec file (or specific example) the cursor is under in vim or the associated test file if there is one in a tmux pane. That allows for quickly running the test without having to leave vim.
      I've dabbled with VSCode a bit and loved the vim plugin! Having the terminals in the window is cool too, kind of like tmux or terminal splits. I could never get it comfortably keyboard-only, but it seems totally possible.
      As a new dev, the whole editor/IDE thing is kinda tough. There are definitely benefits to vim + tmux or emac but there's a bit of a learning curve which can be off-putting. My personal opinion is that it comes down to what you enjoy using the most and following your interests. Dotfile configs like dotmatrix really help make the config process easier, which is great!
      Happy to talk more or make vids about related topics to this stuff, as I think dev env ergonomics is an interesting but sometimes contentious topic.

    • @keith4505
      @keith4505 Před 2 lety

      @@brettcodes Thank you so much for such a detailed reply. Really appreciate it! I’m halfway through your RSpec videos and I really like the process where you code it out first and then gradually refactoring it as you go along. I’ve recently learnt more about clean code and the importance of refactoring but sometimes, when we are learning new stuff (for me its testing), its not always clear how we can make it better especially when existing codebases adopt legacy practices. So for a junior dev like myself this really helps.
      As for dev env ergonomics, it is an interesting topic. I noticed that you use alfred as well. I love alfred! Anything that can make the workflow faster and more enjoyable is always worth a discussion imo. Thats why i chose to explore full vim because ive heard good things about it. Will take a look at dotfiles and continue tinkering with it.
      Hope you get more subs soon. Great content!

    • @brettcodes
      @brettcodes  Před 2 lety +1

      @@keith4505 You're welcome! Thanks for sharing your thoughts and watching through the vids, I appreciate it!

  • @ccJoeMurphy
    @ccJoeMurphy Před 5 lety

    Great vid,
    Could you do something about reporting, is it possible to generate json report, and how can this json report be view in human readable format?

    • @brettcodes
      @brettcodes  Před 3 lety

      Thanks for your kind words! I can't say I've ever done anything like that, but I'm happy to try to help. This doc gives a pretty decent overview of using the `--format j` flag: relishapp.com/rspec/rspec-core/v/2-14/docs/formatters/json-formatter From there, it depends on where the JSON file lives. You could write the output to a file and then open it and parse it with JavaScript or convert it to a CSV spreadsheet. Let me know if there's more info I can share to try to help!

  • @FrenchKettleStation
    @FrenchKettleStation Před 2 lety

    Hi there, fantastic teaching, I have a bit of an auxiliary question, how do you clear your terminal within a tmux instance? There's a glitch on mine where the entire window goes blank, was wondering if you put something in your .tmux.config to make it work like that... Thank you in advance!

    • @brettcodes
      @brettcodes  Před 2 lety

      Hmm, I'm not sure of your exact issue, but here's my tmux config: github.com/brettchalupa/dotfiles/blob/dotmatrix/tmux.conf
      Sometimes switching windows/tabs within tmux can help reset it if it gets funky. Hope ya' get past this issue, sounds frustrating!

  • @rnxrx
    @rnxrx Před 4 měsíci

    с первой секунды видно, что нормальный человек

  • @gerardgauthier4876
    @gerardgauthier4876 Před 2 lety

    So you use magic numbers in the code that's teaching us how to code with RSpec.
    Note: I'm talking about the hungry level value that should be a constant in the Dog class.

    • @brettcodes
      @brettcodes  Před 2 lety

      That's a valid point for sure, I'll work to be more consistent with best practices in future episodes. Thanks for the feedback!

  • @twinklinglicin
    @twinklinglicin Před 5 lety +1

    well goll-dang. i thought this would be another use of a dog class that's boring. nice tips, though, to make it better than average. cheers! i mean woof!

    • @brettcodes
      @brettcodes  Před 3 lety

      I appreciate the kind words! The trivial example could definitely use some more thought in advance for future videos. 😄

  • @jacinyan3893
    @jacinyan3893 Před 3 lety

    Are you still maintaining your channel Brad?

    • @brettcodes
      @brettcodes  Před 3 lety

      I took a break from making screencasts for a bit, but I'm hoping to consistently publish new episodes on Ruby, Rails, web dev, and modern front-end JS tools in the coming weeks and months!

    • @jacinyan3893
      @jacinyan3893 Před 3 lety

      @@brettcodes Yeah, probs more JS coz it is all the rage. You get the idea......

  • @hjeebus
    @hjeebus Před 6 lety +3

    `def feed` should maybe be `def eat`

    • @brettcodes
      @brettcodes  Před 6 lety

      Good point, I agree. I think that'd be more fitting for the class.

  • @KLa187
    @KLa187 Před 6 lety

    Really annoying keyboard sound.

    • @brettcodes
      @brettcodes  Před 6 lety +1

      I'm sorry about that. There's nothing I can do about the keyboard due to the nature of recording the audio while I type.

    • @Kensurs
      @Kensurs Před 6 lety +10

      I personally find it relaxing. And it's an indicator of key presses, which I also prefer. Thanks for this tutorial!