RSpec is a behaviour-driven development (BDD) framework for the Ruby language.
8
votes
2answers
123 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 ...
1
vote
1answer
31 views
DRYing Up RSpec
How would you DRY up this RSpec code?
require "spec_helper"
describe InvoiceMailer do
let(:user) { create(:user) }
let(:student) { create(:student, user: user) }
let(:body) { "And I for one ...
3
votes
1answer
39 views
Pig Latin Translator in Ruby and Rspec
PigLatin Kata
PigLatin Kata
Create a PigLatin class that is initialized with a string
- detail: The string is a list of words seperated by spaces: 'hello world'
- detail: The string is ...
2
votes
3answers
127 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:
PigLatin Kata
Create a PigLatin class that is initialized with a string
...
2
votes
1answer
81 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 ...
0
votes
1answer
51 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:
$kata take word_wrap.rb
WordWrap Kata
Create a "WordWrap" class that is initialized ...
1
vote
1answer
51 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. Thanks!
CalculatorAdvanced Kata
Add Method
Allow the expression to ...
3
votes
1answer
111 views
Is there something in this Ruby and RSpec that absolutely should be done differently?
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
51 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?
require 'spec_helper'
describe ...
2
votes
1answer
63 views
How to separate 2 tangled methods?
I have this (working) code:
class CalendarDay
attr_accessor :from_month, :to_month, :year
def self.line_of_day_numbers(month,year,start,offset)
@line=''
@offset=offset
finish = ...
2
votes
1answer
83 views
General thoughts on the style of this rspec-rails test
Here's a test from a Rails app I'm working on. I want to know if I'm using describe, let, before, expect, etc in the proper way. Any feedback is appreciated:
It is an integration test using capybara ...
3
votes
1answer
366 views
Can I improve the way this model RSpec is written?
I'm new to RSpec and testing in general. I've come up with a spec for testing my Content model and I need some feedback 'cause I think there are many improvements that can be done. I don't know if the ...
1
vote
1answer
54 views
Refactor specs for service class methods
Service Class
# services/search.rb
class Search
include Rails.application.routes.url_helpers
include ActionView::Helpers::TagHelper
def initialize(term, app_ids)
@term = term
@app_ids ...
1
vote
1answer
62 views
Converting tests to specs
I use RSpec but in a way I would use any xUnit framework. Can this snippet be refactored to look more BDD like (using subject and stuff)?
describe Time do
describe ".from_sql" do
it "parses ...
4
votes
2answers
4k views
RSpec integration tests for a simple Rails API
The Model is simple. A Player class with three attributes: first_name, last_name, and team_id.
I'm just trying to get a handle on TDD for what will expand into a much more robust API. Below is my ...
3
votes
1answer
139 views
How might I make this code more DRY?
I have the following Ruby code in an RSpec file:
describe "order" do
before do
LIST_LENGTH ||= 10
@skills = FactoryGirl.create_list(:skill, LIST_LENGTH)
@developer = ...
5
votes
2answers
328 views
Spoj's 1st problem in tdd using Ruby
I am pretty new to TDD and is following problems on spoj.pl for practice. I need help with following code; it was my first attempt.
Problem: Your program is to use the brute-force approach in order ...
1
vote
1answer
481 views
Is the comparing active record result with array of object in rspec test flexible?
Is the test flexible?
describe "self.sort" do
before(:each) do
@tee = FactoryGirl.create :author, nickname: "tee jia hen", user: FactoryGirl.create(:user)
@jon = FactoryGirl.create ...
1
vote
1answer
185 views
How to refactor my controller specs?
In my project (https://github.com/GCorbel/comment-my-projects) I have this kind of code to test my controllers.
#encoding=utf-8
require 'spec_helper'
describe ProjectsController do
let!(:project) ...
2
votes
3answers
176 views
First BDD/RSpec tests, would like some review regarding idioms, conventions and style
This is my first attempt at BDD and RSpec. I'm more of a C# xUnit kind of guy.
I wrote this class while developing a 2D random tile map generator (just for fun). The project is still ongoing.
I ...
1
vote
1answer
108 views
Rspec Request always break when teammate push some changes, how to improve?
This is my rspec integration test for user , it always break when my teammate change something , how do i improve this?
describe "Users" do
before(:each) do
populate_role
end
describe ...
2
votes
1answer
1k views
Tidying scaffolded Rails controller spec with subject/let
I was just looking at a standard scaffolded Rails controller spec, and tried to get it to use subject or let blocks, and failed miserably ... can subject or let tidy controller specs the same as it ...
2
votes
1answer
248 views
What can I do to improve my first RSpec test
I'm relatively familiar with Ruby, but I'm brand new to testing my code. I decided to use RSpec because as it seems like a popular option and wrote a basic Rock Paper Scissors game to be tested.
The ...