Frank: What is a stack?
Linda: This is a data structure that stores objects in the order “first entered, last exited” or “last entered, first exited”. Usually this structure has an API with methods such as push () and pop (). Sometimes there is a peek () method.
Frank: What does the push () method do?
Linda: The push () method takes an input object, for example, foo, and places it in an internal container, for example, an array. The push () method usually returns nothing.
Frank: What happens if you push two objects to the push () method, for example, foo first and then bar?
Linda: The second bar object should be at the top of the conceptual stack containing at least two objects, so when calling the pop () method, the bar object should be retrieved first, before the first foo object. If the pop () method is called again, the foo object should be returned and the stack should be empty (it is assumed that there was nothing in it before we added these two objects).
Frank: So the pop () method removes the very last element that was added to the stack?
Linda: Yes, the pop () method should remove the top element, and it is assumed that there are elements in the stack to remove them. The peek () method works in the same way, but the object is not deleted. The peek () method should leave the top item on the stack.
Frank: What happens if you call the pop () method when nothing has been added to the stack?
Linda: The pop () method should throw an exception indicating that nothing has been added to the stack yet.
Frank: What happens if you execute the push () command null?
Linda: The stack should throw an exception, since null is not a valid value for the push () method.
[sudo] gem install rspecor
git clone git: //github.com/dchelimsky/rspec.gitLet's imagine that your customer is a bank. We illustrate, once again, the dialogue with the customer, in the style of BDD:
cd rspec
rake gem
rake install_gem
You: Please describe how the account should be after its creation?
Customer: The account must have a balance of $ 0.
describe Account, " when first created" do
before do
@account = Account. new
end
it "should have a balance of $0" do
@account.balance.should eql(Money. new (0, :dollars))
end
after do
@account = nil
end
end
* This source code was highlighted with Source Code Highlighter .
Account, when first created
- should have a balance of $ 0
describe Thing do
before(:all) do
# This is run once and only once, before all of the examples
# and before any before(:each) blocks.
end
before(:each) do
# This is run before each example.
end
before do
# :each is the default, so this is the same as before(:each)
end
it "should do stuff" do
...
end
it "should do more stuff" do
...
end
after(:each) do
# this is before each example
end
after do
# :each is the default, so this is the same as after(:each)
end
after(:all) do
# this is run once and only once after all of the examples
# and after any after(:each) blocks
end
end
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/52929/
All Articles