Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug - reused the same args for different scenarios.

  • Loading branch information...
commit 5ad46f658ce650de858f03e984491667254feb83 1 parent b96e790
@andreasronge authored
Showing with 17 additions and 3 deletions.
  1. +4 −3 lib/rspec-apigen/given.rb
  2. +13 −0 spec/api/account_spec.rb
View
7 lib/rspec-apigen/given.rb
@@ -7,17 +7,17 @@ class Given
attr_accessor :return
- # list_of_args - the list of arguments current method accept
+ # args - the list of arguments current method accept
# When the given block is evaluated in this method
# the Given#args will return a hash of name or argument and its value.
- def initialize(context, method, list_of_args, given_caller, &block)
+ def initialize(context, method, args, given_caller, &block)
this = self # so we can access it as closure
@arg = Object.new
@args = {}
@fixtures = {}
block_arg = nil
- list_of_args.find_all { |a| a.kind_of?(Argument) }.each do |a|
+ args.find_all { |a| a.kind_of?(Argument) }.each do |a|
MetaHelper.create_singleton_method(@arg, "#{a.name}=") do |val|
this.args[a.name] = val
end
@@ -32,6 +32,7 @@ def initialize(context, method, list_of_args, given_caller, &block)
end
end
+ list_of_args = args.clone
context.it "no arguments" do
# create the arguments
MetaHelper.create_singleton_method(self, :arg) { this.arg }
View
13 spec/api/account_spec.rb
@@ -27,6 +27,19 @@
it { subject.currency.should == 'USD' } # given.currency }
end
end
+
+ Scenario 'account and currency has valid values' do
+ Given do
+ arg.amount = 10
+ arg.currency = 'USD'
+ end
+
+ Return "an Account with given amount and currency" do
+ it { subject.balance.should == 10 } #given.amount }
+ it { subject.currency.should == 'USD' } # given.currency }
+ end
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.