Skip to content

Add an initial setup for RSpec examples. #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.bundle
bin/configlet
bin/configlet.exe
Gemfile.lock
/Gemfile.lock
Copy link
Member

@kotp kotp Jun 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about this but I wonder if this should be:

Gemfile.lock
# Do track the exercises Gemfile.lock files
!/exercises/*/Gemfile.lock

This way, any other ones are still ignored, or must be explicitly added to the project.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tells git to ignore the Gemfile.lock at the repo root, so it will work (in fact is preferred).

Copy link
Member

@kotp kotp Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which "This"? The one that I propose does the same, but specifically also says to NOT ignore the Gemfile.lock in each of the exercise subfolders (but only the subfolder.), while also ignoring Gemfile.lock anywhere else.

13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FILEEXT := "rb"
EXAMPLE := "example.$(FILEEXT)"
SRCFILE := "$(shell echo $(ASSIGNMENT) | sed 's/-/_/g')"
TSTFILE := "$(SRCFILE)_test.$(FILEEXT)"
SPECFILE := "$(SRCFILE)_spec.$(FILEEXT)"
# Any additional arguments, such as -p for pretty output and others
ARGS ?= ""

Expand All @@ -22,10 +23,13 @@ test-assignment:
@echo ""
@echo ""
@echo "----------------------------------------------------------------"
@pwd
@echo "running tests for: $(ASSIGNMENT)"
@cp -r ./exercises/$(ASSIGNMENT)/* $(OUTDIR)
@cp -r ./exercises/$(ASSIGNMENT)/.rspec $(OUTDIR)/.rspec
@cp ./exercises/$(ASSIGNMENT)/$(EXAMPLE) $(OUTDIR)/$(SRCFILE).$(FILEEXT)
@ruby -I./lib -rdisable_skip.rb $(OUTDIR)/$(TSTFILE) $(ARGS)
@./bin/rspec-test-in $(OUTDIR)
@rm -rf $(OUTDIR)

# all tests
Expand All @@ -34,3 +38,12 @@ test:
ASSIGNMENT=$$assignment $(MAKE) -s test-assignment || exit 1;\
done

seed_rspec:
@for assignment in $(ASSIGNMENTS); do \
ASSIGNMENT=$$assignment $(MAKE) -s seed_individual_assignment_with_rspec || exit 1;\
done

seed_individual_assignment_with_rspec:
@cd ./exercises/$(ASSIGNMENT) && bundle init && echo 'gem "rspec", "~> 3.4.0"' >> Gemfile || exit 0
@cd ./exercises/$(ASSIGNMENT) && bundle install
@cd ./exercises/$(ASSIGNMENT) && echo '--color\n--order=random\n--pattern *_spec.rb' > .rspec
4 changes: 4 additions & 0 deletions bin/rspec-test-in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

CWD=`pwd`
cd $1 && bundle install && bundle exec rspec -r $CWD/lib/disable_rspec_skip.rb
3 changes: 3 additions & 0 deletions exercises/wordy/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--color
--order=random
--pattern *_spec.rb
6 changes: 6 additions & 0 deletions exercises/wordy/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true
# A sample Gemfile
source "https://rubygems.org"

# gem "rails"
gem "rspec", "~> 3.4.0"
26 changes: 26 additions & 0 deletions exercises/wordy/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)

PLATFORMS
ruby

DEPENDENCIES
rspec (~> 3.4.0)

BUNDLED WITH
1.12.5
136 changes: 136 additions & 0 deletions exercises/wordy/wordy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
require_relative "./wordy"

RSpec.describe WordProblem do
it "can add one to one" do
problem = WordProblem.new("What is 1 plus 1?")

expect(problem.answer).to eq(2)
end

it "can add two to fifty three" do
skip "fix this test second - delete the `skip` lines to enable individual tests"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought pending was the rspec way to "skip"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@kotp kotp Jun 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, it has been a long time since I have used RSpec.

When you say "Here" do you mean "Here as in at RSpec" or "Here as in on exercism"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as in "for the exorcism examples"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad I asked.

If it is idiomatic for RSpec to use pending, then we should use pending. Exercism should not influence this, the tests, if we provide them, should be idiomatic and instructive. The documentation states to use skip only due to the use of it in regards to Minitest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending is pretty confusing in Rspec, I think we should stick with skip. pending actually runs the example and reports errors/failures. That noise is confusing because despite big ugly stack traces, pending examples won't fail the run. Quite the opposite, actually. pending examples actually fail the run if a pending scenario passes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think skipped is what we're looking for. It should always be skipped, until they delete it. It's not temporarily skipped because we think we have a bug.

Is there a way to not have the verbose output about it being skipped? I'm trying to avoid noisy output. In this context (exercism) it's not intended as team-wide communication.


problem = WordProblem.new('What is 53 plus 2?')

expect(problem.answer).to eq(55)
end

it "can add negative numbers together" do
skip "fix this test third"

problem = WordProblem.new('What is -1 plus -10?')

expect(problem.answer).to eq(-11)
end

it "can add larger numbers together" do
skip "fix this test fourth"

problem = WordProblem.new('What is 123 plus 45678?')

expect(problem.answer).to eq(45_801)
end

it "can subtract numbers from each other" do
skip "fix this test fifth"

problem = WordProblem.new('What is 4 minus -12?')

expect(problem.answer).to eq(16)
end

it "can multiply numbers together" do
skip "fix this test sixth"

problem = WordProblem.new('What is -3 multiplied by 25?')

expect(problem.answer).to eq(-75)
end

it "can divide two numbers" do
skip "fix this test seventh"

problem = WordProblem.new('What is 33 divided by -3?')

expect(problem.answer).to eq(-11)
end

it "can add numbers together multiple times" do
skip "fix this test eight"

question = 'What is 1 plus 1 plus 1?'
problem = WordProblem.new(question)

expect(problem.answer).to eq(3)
end

it "can add and then subtract a number" do
skip "fix this test ninth"

question = 'What is 1 plus 5 minus -2?'
problem = WordProblem.new(question)

expect(problem.answer).to eq(8)
end

it "can subtract numbers twice" do
skip "fix this test tenth"

question = 'What is 20 minus 4 minus 13?'
problem = WordProblem.new(question)

expect(problem.answer).to eq(3)
end

it "can subtract then add a number" do
skip "fix this test eleventh"

question = 'What is 17 minus 6 plus 3?'
problem = WordProblem.new(question)

expect(problem.answer).to eq(14)
end

it "can multiply numbers twice" do
skip "fix this test twelth"

question = 'What is 2 multiplied by -2 multiplied by 3?'
problem = WordProblem.new(question)

expect(problem.answer).to eq(-12)
end

it "can add then multiply numbers" do
skip "fix this test thirtheenth"

question = 'What is -3 plus 7 multiplied by -2?'
problem = WordProblem.new(question)

expect(problem.answer).to eq(-8)
end

it "can divide numbers twice" do
skip "fix this test fourteenth"

question = 'What is -12 divided by 2 divided by -3?'
problem = WordProblem.new(question)

expect(problem.answer).to eq(2)
end

it "can't do advanced math" do
skip "fix this test fifteenth"

problem = WordProblem.new('What is 53 cubed?')

expect { problem.answer }.to raise_error(ArgumentError)
end

it "can't answer irrelevant questions" do
skip "fix this test sixteenth"

problem = WordProblem.new('Who is the president of the United States?')

expect { problem.answer }.to raise_error(ArgumentError)
end
end
4 changes: 4 additions & 0 deletions lib/disable_rspec_skip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RSpec::Core::Pending.class_eval do
def skip(*args)
end
end