Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated compile feature to match and cover required acceptance.

Thanks to David Chelimsky for the suggestions on irc.
  • Loading branch information...
commit 4fcf40073fe878e7d53dc7ae18cfe10c157462b9 1 parent 835b0d3
@luislavena luislavena authored
View
39 features/compile.feature
@@ -4,51 +4,50 @@ Feature: Compile C code into Ruby extensions.
As a Gem developer.
I want rake tasks compile source code for me.
- Scenario: Compile single extension
+ Scenario: compile single extension
Given a safe project directory
And scaffold code for extension 'extension_one'
And 'tmp' folder is deleted
When rake task 'compile' is invoked
- And rake task 'compile' succeeded
- Then binary extension 'extension_one' do exist in 'lib'
+ Then rake task 'compile' succeeded
+ And binary extension 'extension_one' do exist in 'lib'
And 'tmp' folder is created
- Scenario: Not recompile unmodified extension
+ Scenario: not recompile unmodified extension
Given a safe project directory
And scaffold code for extension 'extension_one'
- And binary extension 'extension_one' do exist in 'lib'
- And intermediate files for extension 'extension_one' do exist in 'tmp'
+ And I've already successfully executed rake task 'compile'
+ And not changed any file since
When rake task 'compile' is invoked
- And rake task 'compile' succeeded
- Then output of rake task 'compile' does not match /extension_one/
+ Then rake task 'compile' succeeded
+ And output of rake task 'compile' do not contain /extension_one/
Scenario: recompile extension when source is modified
Given a safe project directory
And scaffold code for extension 'extension_one'
- And binary extension 'extension_one' do exist in 'lib'
- And intermediate files for extension 'extension_one' do exist in 'tmp'
+ And I've already successfully executed rake task 'compile'
When touching 'source.c' file of extension 'extension_one'
And rake task 'compile' is invoked
- And rake task 'compile' succeeded
- Then output of rake task 'compile' does match /extension_one/
+ Then rake task 'compile' succeeded
+ And output of rake task 'compile' contains /extension_one/
- Scenario: Compile multiple extensions
+ Scenario: compile multiple extensions
Given a safe project directory
And scaffold code for extension 'extension_one'
And scaffold code for extension 'extension_two'
And 'tmp' folder is deleted
When rake task 'compile' is invoked
- And rake task 'compile' succeeded
- Then binary extension 'extension_one' do exist in 'lib'
+ Then rake task 'compile' succeeded
+ And binary extension 'extension_one' do exist in 'lib'
And binary extension 'extension_two' do exist in 'lib'
And 'tmp' folder is created
- Scenario: Compile one extension instead of all present
+ Scenario: compile one extension instead of all present
Given a safe project directory
And scaffold code for extension 'extension_one'
And scaffold code for extension 'extension_two'
When rake task 'compile:extension_one' is invoked
- And rake task 'compile:extension_one' succeeded
- Then output of rake task 'compile:extension_one' does not match /extension_two/
- And binary extension 'extension_one' must exist in 'lib'
- And binary extension 'extension_two' must not exist in 'lib'
+ Then rake task 'compile:extension_one' succeeded
+ And output of rake task 'compile:extension_one' do not contain /extension_two/
+ And binary extension 'extension_one' do exist in 'lib'
+ And binary extension 'extension_two' do not exist in 'lib'
View
24 features/step_definitions/compilation.rb
@@ -4,21 +4,18 @@
setup_source_for extension_name
end
-Given /^binary extension '(.*)' do exist in '(.*)'$/ do |extension_name, folder|
- setup_binaries_for extension_name, folder
-end
-
-Given /^intermediate files for extension '(.*)' do exist in '(.*)'$/ do |extension_name, folder|
- setup_intermediate_files_for extension_name, folder
+Given /^not changed any file since$/ do
+ # don't do anything, that's the purpose of this step!
end
When /^touching '(.*)' file of extension '(.*)'$/ do |file, extension_name|
+ Kernel.sleep 1
FileUtils.touch "ext/#{extension_name}/#{file}"
end
-Then /^binary extension '(.*)' (must|must not) exist in '(.*)'$/ do |extension_name, condition, folder|
+Then /^binary extension '(.*)' (do|do not) exist in '(.*)'$/ do |extension_name, condition, folder|
ext_for_platform = File.join(folder, "#{extension_name}.#{RbConfig::CONFIG['DLEXT']}")
- if condition == 'must'
+ if condition == 'do'
File.exist?(ext_for_platform).should be_true
else
File.exist?(ext_for_platform).should be_false
@@ -63,14 +60,3 @@ def setup_source_for(extension_name)
ext.puts template_extconf(extension_name)
end
end
-
-def setup_binaries_for(extension_name, folder)
- ext_for_platform = File.join(folder, "#{extension_name}.#{RbConfig::CONFIG['DLEXT']}")
- FileUtils.touch ext_for_platform
-end
-
-def setup_intermediate_files_for(extension_name, folder)
- setup_binaries_for(extension_name, folder)
- FileUtils.touch "#{folder}/Makefile"
- FileUtils.touch "#{folder}/source.#{RbConfig::CONFIG['OBJEXT']}"
-end
View
27 features/step_definitions/execution.rb
@@ -1,13 +1,19 @@
+Given %r{^I've already successfully executed rake task '(.*)'$} do |task_name|
+ emptyness = `rake #{task_name} 2>&1`
+ puts emptyness
+ raise "rake failed with #{$?.exitstatus}" unless $?.success?
+ puts File.mtime("lib/extension_one.so")
+ puts File.mtime("tmp/extension_one/extension_one.so")
+end
+
When /^rake task '(.*)' is invoked$/ do |task_name|
@output ||= {}
@result ||= {}
- FileUtils.chdir @safe_dir do
- @output[task_name] = `rake #{task_name} 2>&1`
- @result[task_name] = $?.success?
- end
+ @output[task_name] = `rake #{task_name} 2>&1`
+ @result[task_name] = $?.success?
end
-When /^rake task '(.*)' succeeded$/ do |task_name|
+Then /^rake task '(.*)' succeeded$/ do |task_name|
if @result.nil? || !@result.include?(task_name) then
raise "The task #{task_name} should be invoked first."
else
@@ -15,8 +21,11 @@
end
end
-Then /^output of rake task '(.*)' (does|does not) match \/(.*)\/$/ do |task_name, condition, regexp|
- (condition == 'does') ?
- @output[task_name].should(match(%r[#{regexp}])) :
- @output[task_name].should_not(match(%r[#{regexp}]))
+Then /^output of rake task '(.*)' (contains|do not contain) \/(.*)\/$/ do |task_name, condition, regex|
+ puts @output[task_name]
+ if condition == 'contains' then
+ @output[task_name].should match(%r(#{regex}))
+ else
+ @output[task_name].should_not match(%r(#{regex}))
+ end
end
View
2  features/step_definitions/folders.rb
@@ -1,4 +1,6 @@
Given /^a safe project directory$/ do
+ # step back to ROOT
+ Dir.chdir ROOT_PATH
tmp_name = "project.#{Process.pid}"
@safe_dir = File.join(ROOT_PATH, 'tmp', tmp_name)
FileUtils.rm_rf @safe_dir
Please sign in to comment.
Something went wrong with that request. Please try again.