Comments (4)
Matt,
The reason why this is happening is because Goblin executes everything after all the tests are declared. This means that in your first example, the value of the variable "i" in every test declared inside the loop will be the same.
In order to get your example to work you must do something like this:
for i, exp := range expectations {
thing := things[i]
g.It("each thing must be correct", func() {
t.Log(len(thing.List)) // always prints 0
t.Log(len(exp.List)) // always print 0
})
}
Let me know if that works for you.
from goblin.
Sorry for the lack of feedback,
Quick question, can I do something like this (obviously the following code would fail:
for i, exp := range expectations {
g.It("each thing must be correct", func(thing) {
t.Log(len(thing.List))
t.Log(len(exp.List))
}(things[i]))
}
Basically, I'd like to send arguments to my expectation. This isn't required and I understand that the problem I encountered was a scoping bug in my code and I should have found it myself, but I'm curious to what extent, nested functions can cause more scoping issues.
from goblin.
Sorry for taking too long to respond. I get what you're trying to do, and I don't think we need to change goblin in order to accomplish that.
Let me know if this works for you:
g.Describe("test", func() {
for i := 0; i < 5; i++ {
(func(i int) {
g.It("Is pending "+strconv.Itoa(i), func() {
fmt.Println(i)
})
}(i))
}
})
Marcos.
from goblin.
Oh I see, it delays the running of the "It" function since it's nested the
anonymous function. Smart!
On Mon, Dec 2, 2013 at 5:48 PM, Marcos Nils [email protected]:
@mattetti https://github.com/mattetti
Sorry for taking too long to respond. I get what you're trying to do, and
I don't think we need to change goblin in order to accomplish that.Let me know if this works for you:
g.Describe("test", func() {
for i := 0; i < 5; i++ {
(func(i int) {
g.It("Is pending "+strconv.Itoa(i), func() {
fmt.Println(i)
})
}(i))
}})Marcos.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/33#issuecomment-29676801
.
from goblin.
Related Issues (20)
- Error output from testify doesn't use goblin theme HOT 1
- Test hooks should not execute if all tests are skipped HOT 3
- Request for describe comments to be matched with -goblin.run regexp HOT 4
- NotEqual assertions HOT 2
- How to run each test in parallel in test suite? HOT 5
- Is it expected, that Goblin doesn't output anything if all tests pass? HOT 2
- Documentation for Before and After HOT 2
- Can't range over data set inside Describe block HOT 2
- Add support for mocking library HOT 6
- Dep ensures invalid version. HOT 1
- 0 not equal 0x0 HOT 1
- Regexp test selector does not seem to work. HOT 4
- basic error handle for incorrect use of the library HOT 2
- Table driven tests will test only last item HOT 4
- Allow multiple `errors` from failed test HOT 2
- Assertion redeclared during import w/ Gomega HOT 2
- Proposal: Please start using Semantic Versioning HOT 3
- Dependent Tests, skip some subset of tests if the parent test fails HOT 5
- IsNil (mis)behavior on pointers HOT 1
- Concurrency race when running in parallel
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goblin.