Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Questions tagged [rspec]

RSpec is a behaviour-driven development (BDD) framework for the Ruby language.

Filter by
Sorted by
Tagged with
1
vote
1answer
103 views

Rspec test for Rails method to return alphabetically sorted list of tags

I have one model class as listed here: class Post < ActiveRecord::Base has_many :comments def tags comments.map(&:tag).uniq.sort end end and ...
2
votes
0answers
40 views

Validating Amazon CloudFormation templates using Rspec

I have created an open source project that uses Rspec to validate the formatting of AWS::CloudFormation::Init YAML blocks in CloudFormation templates.1 My project is here. Some general concerns: Is ...
1
vote
3answers
105 views

Calculate cryptocurrency gains and losses using the Coinbase API

This class calculates the gains and losses (in USD) from the four leading cryptocurrencies using the Coinbase API. (The full repo can be found here) In addition to general feedback there are some ...
1
vote
1answer
309 views

RSpec test for handling known IP addresses

I want to replace the array of ips with a method (like known_ips or just ips) but I don't know how. I'll use this ...
2
votes
1answer
1k views

Rspec unit test for updating a property of a model

I know how to write simple RSpec tests and unit tests. I just want to know if this is good enough or if there are any improvements I can make. I intend to test the the ...
2
votes
0answers
660 views

Rails CRUD feature specs (RSpec and Capybara)

The following feature spec tests CRUD operations for the users resource in a Rails 4.2.8 application. It includes tests for filtering, sorting and pagination ...
3
votes
1answer
125 views
5
votes
1answer
1k views

Rails & RSpec - Testing API with request specs and shared examples

I have written the following shared examples which are used in multiple request specs to test a namespaced RESTful JSON API. Application details: Rails 4.2, RSpec 3.5, Devise for authentication and ...
3
votes
1answer
453 views

Controller tests (Rails 4.2 and RSpec 3.5)

The following code is a controller spec used in a Rails 4.2 application with RSpec 3.5. I would greatly appreciate your suggestions on how to improve it (e.g., efficiency, readability, maintainability,...
1
vote
0answers
606 views

Unit-testing authorization policies in Rails with RSpec

The following specs test the authorization setup of the Post resource in a Rails 4.2 application. The Pundit gem is used for authorization but I believe the specs ...
1
vote
2answers
70 views

Testing a chance-based class

So, chance, huh? Randomness. I'm looking into how I can test a class whose sole responsibility is to return weighted random results, that is, where there is a set probability of returning true. The ...
3
votes
1answer
147 views

Ruby sudoku solver using backtracking (interview)

I was required to implement the code to a spec file I was provided in Ruby. I was rejected with the message "The quality of your code isn't sufficient for this position". Can you please tell me what ...
1
vote
0answers
21 views

Creating a list of things by looking up multiple sources

I am trying to write a rspec webmock test for a rails PORO model. What this model does is, query bugzilla with a set of filters for a list of bugs and iterate over it such that: The bug ids are used ...
4
votes
1answer
274 views

Marketplace checkout system

I was given the following code challenge as part of an interview process, unfortunately I did not get through to the next stage. Any advice on how I could improve would be very much appreciated. Here ...
0
votes
3answers
892 views

Testing #initialize of class Author

I am trying to test #initialize of class Author: ...
2
votes
1answer
881 views

Ruby FizzBuzz solution with Rspec test

My code makes the four tests pass, but I'm worried I'm missing something. Is the code too simple and not encompassing enough? I'm just beginning to learn so any feedback is welcome! Here's the Rspec ...
2
votes
2answers
82 views

A sequence of mistakes

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see The Genetic Code. The repository with all my up-to-date solutions so far can be found ...
4
votes
1answer
145 views

Simple Ruby program to model a prepaid transit card system

I have written a simple Ruby program to model a transit card system which aims to address the following user stories. I wanted to see whether I could get any feedback on it. My main interest is ...
1
vote
1answer
382 views

Creating a dictionary

I have a Ruby programming task. My code passes all the rspec requirements, but I am not sure if I've done it in the right way. And I'm not quite sure why I need ...
2
votes
1answer
140 views

Rspec controller tests

I wanted to keep my controller tests DRY, readable, and make writing new tests very simple so that it encourages good practices like one assertion per test (if you have to redo a lot of work over and ...
1
vote
0answers
42 views

Geocoding users' IPs

My Rails app geocodes users' IP when they are created and also when they update their data only if they change their city. The geocoding is slowing down my tests ridiculously. This seems to me to be ...
1
vote
3answers
1k views

Checking whether two strings are isomorphic

I was trying to solve a problem to determine if 2 strings are isomorphic. They are isomorphic when each character in string one can be replaced with another character in string 2. Two different ...
5
votes
1answer
301 views

Rspec - testing basic functionality - redundant testing?

Being pretty new to testing, I was wondering how many of these tests make sense. restaurants_controller_spec.rb ...
3
votes
2answers
621 views

Building a chain of responsibility in Ruby to apply transformators on an object

I try to make a middleware stack system in the rack way (but not for HTTP request). Here is the main class: ...
2
votes
3answers
160 views

Controller actions permisson specs

I'm just starting with rails and testing, and not sure what's good way to dry code like this. ...
2
votes
0answers
335 views

Rspec test reuse code for before_filter and method

Consider following example (controller): ...
7
votes
1answer
3k views

RSpec test for pagination

This is a Rspec test for pagination in Rails project. I'm not sure if I should write the test in spec/requests or ...
2
votes
1answer
166 views

DRY-ing up some rspec

I have an rspec spec test that has two sets of the same tests (from 24 Pull Requests). I thought I'd refactor the spec whilst I fixed something else. Normally I just do a basic ...
0
votes
2answers
204 views

Factory Girl in Rails

I have a FactoryGirl page that generates same data but in two different languages. The variable names are the same. How do I write it in the smartest way possible without having to write a huge bunch ...
2
votes
3answers
585 views

RSpec/Capybara tests

There are three scenarios only for when the sign up validations fail, so is there a better way of representing them rather than having 4 scenarios? I don't want to create a model folder so please don'...
8
votes
2answers
3k views

Using I18n in capybara feature specs

Here I am trying to avoid hardcoding in flash messages by using I18n. Also, I have tried to use a CSS selector for submitting the form to make the tests less brittle (I don't really care that much ...
3
votes
1answer
166 views

Mixing Watir::Browser into RSpec

In my previous Watir question I was making a module with session_FF accepting a block. Now I want to make the same but via RSpec. Here is my try: ...
1
vote
2answers
257 views

Removing duplication in RSpec

I’m still relatively new to the TDD scene. I’m writing a Rails app, and some duplication immediately sticks out at me in my first model spec. How else can I approach this? ...
2
votes
1answer
68 views

Unit-testing account transaction code

I'm playing with unit-testing in Ruby. There is a situation that I don't know if is good enough or if I am doing the wrong abstraction. I have two classes: ...
1
vote
2answers
798 views

Various RSpec tests

I've just written my first full batch of RSpec tests and wondered if anyone can comment at a glance on how they might be written easier, more readable, faster etc. There are some pending specs so ...
7
votes
1answer
744 views

Binary converter and sufficient tests

I just finished writing a basic binary conversion class in Ruby. I'm curious to see if anyone has suggestions for improvements. In particular, I'm looking for the cleanest, shortest, most succinct ...
8
votes
1answer
10k views

My first controller rspec test

I'm just started learning TDD with Rails and RSpec. This is my first test for controller. Just plain RESTful UserController that responds with JSON, so it has no new and edit methods. Please review it ...
5
votes
1answer
512 views

BinarySearch Kata in Ruby

I've just completed this binary search kata - which has some weird requirements - and I spent a little while "cleaning" up my code and making it more compact. I would appreciate some feedback on the ...
4
votes
2answers
700 views

RSpec tests for a cash flow model

This is my first model RSpec test: ...
10
votes
2answers
760 views

Cash Register Kata

The Setup This kata is a spin on the old backpack problem. Please give feedback on both the kata itself as well as my solution. I'm not sure if the kata needs to lead the student more or if this is a ...
3
votes
1answer
131 views

RSpec tests for an invoice mailer

How would you DRY up this RSpec code? ...
3
votes
1answer
1k views

Pig Latin Translator in Ruby and Rspec

PigLatin Kata ...
2
votes
3answers
962 views

Pig Latin Code Kata

I've just complete a Pig Latin translator as a code kata and I was hoping someone would review it for me. Here is the kata: ...
2
votes
1answer
505 views

How can this rails controller test be cleaner refactored?

I tend to write quite explicit tests for my rails controllers exposing APIs with two seperate concerns: meeting the defined API-Response with headers headers and the response itself ensuring the ...
1
vote
1answer
256 views

Ruby Kata Gem: WordWrap

I've just completed the WordWrap Kata in the Ruby Kata gem and I'd love some feedback. Thanks! Here's the Kata: ...
2
votes
1answer
345 views

Advanced Calculator Kata

This is the CalculatorAdvanced Kata from the Kata gem. I've just finished it and would love some feedback on my solution. ...
4
votes
1answer
149 views

Weekly flex calculator

This is one of the first RSpec tests I've written, and I'm not really sure what the best practices are etc. My question basically is: what would you do differently? What is good? What is bad? The ...
2
votes
1answer
160 views

Using RSpec subject to setup a test

I find myself using subject blocks in my tests to setup example because it is succinct. However is this considered bad form and can it have undesired consequences? ...
2
votes
1answer
82 views

Displaying the calenday day

I have this (working) code: ...
2
votes
1answer
186 views

Test for a Rails app

Here's a test from a Rails app I'm working on. I want to know if I'm using describe, let, ...