summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTom Black <[email protected]>2015-11-13 00:26:17 -0500
committerTom Black <[email protected]>2015-11-13 00:26:17 -0500
commit7a96ea1932a7d9a4dd4392bfad1f60c5beb06c33 (patch)
tree3fb1f779fcd3fe28eb10beb46749ee8f1310d74d
parentdfe8e70159a3f2f47baceead173e55e9e29f91f7 (diff)
downloadruby2d-7a96ea1932a7d9a4dd4392bfad1f60c5beb06c33.tar.gz
ruby2d-7a96ea1932a7d9a4dd4392bfad1f60c5beb06c33.zip
Adding RSpec and some tests
-rw-r--r--.rspec2
-rw-r--r--Rakefile20
-rw-r--r--spec/color_spec.rb38
-rw-r--r--spec/spec_helper.rb9
4 files changed, 62 insertions, 7 deletions
diff --git a/.rspec b/.rspec
new file mode 100644
index 0000000..83e16f8
--- /dev/null
+++ b/.rspec
@@ -0,0 +1,2 @@
+--color
+--require spec_helper
diff --git a/Rakefile b/Rakefile
index 022193e..e513ad5 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,11 +1,17 @@
-# require 'rake/testtask'
+require 'rspec/core/rake_task'
task default: 'all'
-# Rake::TestTask.new do |t|
-# t.test_files = FileList['test/*_test.rb']
-# t.verbose = true
-# end
+def run_test(file)
+ Rake::Task['build'].invoke
+ Rake::Task['spec'].invoke
+ system "( cd tests/ ; ruby #{file}.rb )"
+end
+
+desc "Run the specs"
+RSpec::Core::RakeTask.new do |t|
+ t.pattern = "spec/*spec.rb"
+end
desc "Build Gem"
task :build do
@@ -27,8 +33,8 @@ task :testcard do
end
-desc "Test and Build"
+desc "Test and build"
task :all do
- # Rake::Task['test'].invoke
Rake::Task['build'].invoke
+ Rake::Task['spec'].invoke
end
diff --git a/spec/color_spec.rb b/spec/color_spec.rb
new file mode 100644
index 0000000..0b63d8d
--- /dev/null
+++ b/spec/color_spec.rb
@@ -0,0 +1,38 @@
+require 'ruby2d'
+
+
+RSpec.describe Ruby2D::Color do
+
+ describe '#is_valid?' do
+
+ it 'determines if a color string is valid' do
+ pending 'need hash of valid strings'
+ expect(Ruby2D::Color.is_valid? 'red').to be true
+ expect(Ruby2D::Color.is_valid? 'balloons').to be false
+ end
+
+ it 'determines if an array is a valid color' do
+ expect(Ruby2D::Color.is_valid? [1.0, 0, 0, 1.0]).to be true
+ expect(Ruby2D::Color.is_valid? [1.0, 0, 0]).to be false
+ end
+
+ it 'prevents allow color values out of range' do
+ expect(Ruby2D::Color.is_valid? [1.0, 0, 0.0, 255]).to be true
+ expect(Ruby2D::Color.is_valid? [1.2, 0, 0, 0]).to be false
+ expect(Ruby2D::Color.is_valid? [-0.1, 0, 0, 0]).to be false
+ expect(Ruby2D::Color.is_valid? [255, 255, 256, 255]).to be false
+ expect(Ruby2D::Color.is_valid? [-1, 0, 127, 255]).to be false
+ end
+
+ end
+
+
+ describe '#new' do
+
+ it 'raises error on bad color' do
+ expect { Ruby2D::Color.new 42 }.to raise_error Ruby2D::Error
+ end
+
+ end
+
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..82b6100
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,9 @@
+RSpec.configure do |config|
+ config.expect_with :rspec do |expectations|
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
+ end
+
+ config.mock_with :rspec do |mocks|
+ mocks.verify_partial_doubles = true
+ end
+end